All Implemented Interfaces:
Configurable, KeyVal.Mixin, UtilsMixin

@CheckAtLeastOneNotEmpty(fieldNames={"commandString","file"}) public class ShellTask extends Task<ShellTask>
Executes a shell script.

/*
 * 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 Details

  • Method Details

    • loadProfile

      public void loadProfile()
    • toExecTask

      public ExecTask toExecTask()
    • getShell

      public String getShell()
      The shell command to be executed bash, zsh. Must be on PATH.
    • getWorkingDir

      public String 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

      public String getCommandString()
      The command string to be executed using the shell's -c argument

      Note: Must either specify commandString or file

      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

      public String getFile()
      The file to be passed to the shell.

      Note: Must either specify commandString or file

      This is the same as running "bash FILE"

    • getLogin

      public Boolean 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

      public void setShell(String shell)
      The shell command to be executed bash, zsh. Must be on PATH.
    • setWorkingDir

      public void setWorkingDir(String workingDir)
      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

      public void setCommandString(String commandString)
      The command string to be executed using the shell's -c argument

      Note: Must either specify commandString or file

      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

      public void setFile(String file)
      The file to be passed to the shell.

      Note: Must either specify commandString or file

      This is the same as running "bash FILE"

    • setLogin

      public void setLogin(Boolean login)
      Sets the -l or --login argument to your shell. This will usually load up the .profile (or equivalent) of the shell.
      See Also:
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Task<ShellTask>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Task<ShellTask>
    • toString

      public String toString()
      Overrides:
      toString in class Task<ShellTask>