dfds / ado-deployment-templates

A collection of DFDS best practice awpdeployment templates for Azure DevOps
MIT License
0 stars 1 forks source link

Azure pipeline variable validation does not work #2

Closed KPLauritzen closed 2 years ago

KPLauritzen commented 3 years ago

There is a step in the sample azure pipeline where you are checking if the required variables are available. See https://github.com/dfds/ado-deployment-templates/blob/e9b6b1c1374cfa650b673d694d629122861d497e/ASP.NET%20Core%20sample/azure-pipelines/azure-pipelines.yaml#L37

That does not work. I have made a minimal pipeline with that step and no env variables present. See https://dfds.visualstudio.com/Smart%20Data/_build/results?buildId=399157&view=logs&j=c2c68960-4438-5f02-6a48-42e214c5aa43&t=922c0c65-55f5-5296-e6a9-03d3274dfca1

The command bash -c '[[ -z $AWS_PROFILE || -z $SAML2AWS_ROLE || -z $SAML2AWS_PASSWORD || -z $SAML2AWS_USERNAME ]] && exit 1 || true' works as intended if I run it in my local bash terminal.

avnes commented 2 years ago

Hi @KPLauritzen

This has now been fixed by feeding the error back to Azure DevOps when a non-zero exit code is detected:

- task: Bash@3
      inputs: 
        targetType: inline
        script: |
          echo 'Checking for required authentication variables...'
          bash -c '[[ -z $AWS_PROFILE || -z $SAML2AWS_ROLE || -z $SAML2AWS_PASSWORD || -z $SAML2AWS_USERNAME ]] && exit 1 || true'

          if [[ $? -ne 0 ]]; then
            echo 'Some environment variables are not set or they have empty values...'
            exit 1
          fi
      displayName: Testing environment variables
avnes commented 2 years ago

Template has been updated accordingly.