Class ShellTask
- All Implemented Interfaces:
Configurable
,KeyVal.Mixin
,UtilsMixin
/*
* Copyright 2022 Thoughtworks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
tasks {
// for simple evaluation of environment variables
// equivalent of `bash -c 'rsync file user@${REMOTE_HOST}:'`
bash {
commandString = 'rsync file user@${REMOTE_HOST}:'
}
// to explicitly call a shell script using `bash deploy.sh`
bash {
file = "./deploy.sh"
}
// to load up `.profile` or equivalent. This is particularly useful if you're using shell shims like `rvm` or `nvm`
bash {
login = true
// you can also invoke the following method:
loadProfile()
}
// if you want to use a custom shell
shell {
shell = '/bin/fish'
file = './deploy.sh'
}
}
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
The command string to be executed using theshell
's-c
argumentgetFile()
The file to be passed to theshell
.getLogin()
Sets the-l
or--login
argument to your shell.getShell()
The shell command to be executedbash
,zsh
.The directory in which the script or command is to be executed.int
hashCode()
void
void
setCommandString
(String commandString) The command string to be executed using theshell
's-c
argumentvoid
The file to be passed to theshell
.void
Sets the-l
or--login
argument to your shell.void
The shell command to be executedbash
,zsh
.void
setWorkingDir
(String workingDir) The directory in which the script or command is to be executed.toString()
Methods inherited from interface cd.go.contrib.plugins.configrepo.groovy.dsl.mixins.Configurable
configure
Methods inherited from interface cd.go.contrib.plugins.configrepo.groovy.dsl.mixins.KeyVal.Mixin
lookup, lookup
Methods inherited from interface cd.go.contrib.plugins.configrepo.groovy.dsl.mixins.UtilsMixin
sanitizeName
-
Constructor Details
-
ShellTask
public ShellTask() -
ShellTask
-
-
Method Details
-
loadProfile
public void loadProfile() -
toExecTask
-
getShell
The shell command to be executedbash
,zsh
. Must be on PATH. -
getWorkingDir
The directory in which the script or command is to be executed.Note that this directory is relative to the directory where the agent checks out the materials.
-
getCommandString
The command string to be executed using theshell
's-c
argumentNote: Must either specify
commandString
orfile
This is the same as running:
/*
* Copyright 2022 Thoughtworks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// equivalent of `bash -c "YOUR_COMMAND_STRING"`
shell {
commandString = ""
}
-
getFile
The file to be passed to theshell
.Note: Must either specify
commandString
orfile
This is the same as running
"bash FILE"
-
getLogin
Sets the-l
or--login
argument to your shell. This will usually load up the.profile
(or equivalent) of the shell.- See Also:
-
setShell
The shell command to be executedbash
,zsh
. Must be on PATH. -
setWorkingDir
The directory in which the script or command is to be executed.Note that this directory is relative to the directory where the agent checks out the materials.
-
setCommandString
The command string to be executed using theshell
's-c
argumentNote: Must either specify
commandString
orfile
This is the same as running:
/*
* Copyright 2022 Thoughtworks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// equivalent of `bash -c "YOUR_COMMAND_STRING"`
shell {
commandString = ""
}
-
setFile
The file to be passed to theshell
.Note: Must either specify
commandString
orfile
This is the same as running
"bash FILE"
-
setLogin
Sets the-l
or--login
argument to your shell. This will usually load up the.profile
(or equivalent) of the shell.- See Also:
-
equals
-
hashCode
public int hashCode() -
toString
-