Azure-pipelines-agent: Shell to run commands from `.vsts-ci.yml` setup incorrectly

Created on 3 Sep 2018  路  9Comments  路  Source: microsoft/azure-pipelines-agent

VSTS Type and Version

VisualStudio.com https://caringcompany.visualstudio.com/

What's not working?

Given the following vsts-ci.yml file:

queue: Hosted Linux Preview

steps:
- script: |
    false
    true

The expected behavior is:

  • false is executed. Then the build stops and is marked as failure because false exited with a non-zero exit status.

The actual behavior is:

  • false is executed. The non-zero exit status is ignored.
  • true is executed. The build is marked as success.

The shell setup for the shell that is spawned for executing the commands inside .vsts-ci.yml is wrong. Build shells should be setup with errexit and pipefail flags enabled. Other setups do not make sense in build environments.

Workaround:

  • Start with set -e and set -o pipefail
  • Do not put multiple shell lines in a .vsts-ci.yml file. Instead

    • use a shell script with a bash shell that runs set -e for errexit and set -o pipefail for pipefail (or sets the corresponding environment variable),

    • or use GNU make to run your commands.

documentation

Most helpful comment

actually, since that just equates to an inline script task we could document that's what script: ... does for bash??

All 9 comments

The challenge with doing that is people use the system to automate many different types of things with shell scripts not just builds and the behavior of the script task has been the same for years. Changing that now would likely break many people and may actually be an undesirable behavior given the scenario.

@chrisrpatterson - what about adding it as an option to the released script tasks (default to false) but script: ... first class in yaml pass that option as true. yaml is still in preview

actually, since that just equates to an inline script task we could document that's what script: ... does for bash??

We have created a new repository for all YAML related issues, please move the current issue to there.
https://github.com/Microsoft/azure-pipelines-yaml

@christianhujer have you tried this:

pool: hosted ubuntu 1604
steps:
- script: false
- script: true

closing since answered. if anything left to answer, see the point above about moving to azure-pipelines-yaml

@ericsciple Does this run one bash or separate bashs? If it runs separate bashs, it's again not a solution, as it would mean that the first bash cannot create environment for the second bash to use.

@TingluoHuang To me it's unclear whom you are addressing regarding moving this issue. Do you expect me to move the issue, or somebody from Microsoft / Azure?

This bash step worked for me:

      - bash:  echo "##vso[task.setvariable variable=shellopts]errexit"
        displayName: "Force exit on error (bash)"

Otherwise you need to use set -e on every multi-line bash step.

Was this page helpful?
0 / 5 - 0 ratings