jenkinsci / azure-cli-plugin

A Jenkins plugin to use Azure CLI for managing Azure resources.
https://plugins.jenkins.io/azure-cli/
MIT License
5 stars 18 forks source link

Az errors not failing build #10

Open ghost opened 6 years ago

ghost commented 6 years ago

We have a long pipeline that consists of a lot of az cli calls, but the stage/pipeline doesn't fail if the CLI runs into issues. It would be really helpful if that was possible (or maybe configurable to fail on errors)

Thanks

torosent commented 6 years ago

Which command did you try ? I tried

node {
    azureCLI commands: [[exportVariablesString: '/ipAddress|PUBLIC_IP', script: 'az1 network public-ip show --resource-group test-n pip']], principalCredentialId: 'superSecretCredential'
    sh "echo ${PUBLIC_IP}"
}

and the build failed as expected.

Notice that i changed az to az1. It also failed with other variations of the command.

It didn't fail if i changed the exportVariablesString to a non existing value in the response.

bfederau commented 5 years ago
...
       stage('Check') {
            steps {
                azureCLI commands: [
                    [script: "azu group exists --resource-group ${params.azResourceGroup}", exportVariablesString: '']
                ], principalCredentialId: "${CREDENTIAL_ID}"
            }
        }
        stage('Deploy') {
            steps {
                azureCLI commands: [
                    [script: "az group deployment create --resource-group ${params.azResourceGroup} --template-file ${TEMPLATE_FILE} --parameters @${PARAMETER_FILE} --parameters storageAccountName=${params.azStorageAccountName} vaultName=${params.azKeyVaultName}", exportVariablesString: '']
                ], principalCredentialId: "${CREDENTIAL_ID}"
            }
        }
...

The above pipeline snippet does not stop in the Check stage when the cli command fails (used azu instead of az as an example). It always executes the Deploy stage! But in the end the pipeline was marked as failed. I would have expected that if a az cli command fails the stage will be marked as failed and the following stages wont be executed.

How can I achieve that the pipeline stops at the stage where the azure cli has failed?

My environment: Ubuntu 18.04, Jenkins 2.180, Azure CLI 2.0.66-1~bionic and Azure Cli Plugin: 0.9