Skip to main content

Shell interpreter

The Shell interpreter executes shell commands or scripts as an action in a Chef Courier job, and can be run on both Linux and Windows operating systems.

Use the linux or windows commands in your Courier job definition to execute Linux and Windows commands. The syntax is as follows:

"command": {
    "linux": ["<LINUX_COMMAND>"],
    "windows": ["<WINDOWS_COMMAND>"]
}

Working directory

The Shell interpreter sets a default working directory relative to the current user’s home directory. Depending on the platform, the home directory is determined by either the $HOME or %USERPROFILE% environment variable. If these variables aren’t set in the environment, then it attempts to use a either a platform-specific default value or it fails with an error.

You can set a different working directory in an action that uses the Shell interpreter in actions.steps.[].inputs.dir.

For example:

{
  ...
  "actions":{
    ...
    "steps":[
      {
        ...
        "inputs":{
          "dir":"/path/to/working/directory/"
        }
      }
    ]
  }
}

Example

The following job executes a shell command:

{
  "name":"a sample job",
  "description":"a simple job to demonstrate a shell command execution",
  "scheduleRule":"immediate",
  "exceptionRules":[

  ],
  "target":{
    "executionType":"sequential",
    "groups":[
      {
        "timeoutSeconds":160,
        "batchSize":{
          "type":"number",
          "value":1
        },
        "distributionMethod":"rolling",
        "successCriteria":[
          {
            "numRuns":{
              "type":"percent",
              "value":100
            },
            "status":"success"
          }
        ],
        "nodeListType":"nodes",
        "nodeIdentifiers":[
          "--NODE1--"
        ]
      }
    ]
  },
  "actions":{
    "accessMode":"agent",
    "steps":[
      {
        "interpreter":{
          "skill":{
            "minVersion":"1.0.0"
          },
          "name":"chef-platform/shell-interpreter"
        },
        "command":{
          "linux":[
            "sleep 10"
          ],
          "windows":[
            "echo 'some sample content'"
          ]
        },
        "inputs":{
          "dir":"/Users/username/path/"
        },
        "expectedInputs":{

        },
        "outputFieldRules":{

        },
        "retryCount":2,
        "failureBehavior":{
          "action":"retryThenFail",
          "retryBackoffStrategy":{
            "name":"none",
            "delaySeconds":0,
            "arguments":[
              1,
              3,
              5
            ]
          }
        },
        "limits":{

        },
        "conditions":[

        ]
      }
    ]
  }
}

Thank you for your feedback!

×