I have a pipeline part like following:
stages:
- stage: A
jobs:
- job: build
steps:
- script: docker image build repo/myimage:1
- script: docker push repo/myimage:1
And I want to add a new step to check if "repo/myimage:1
" pushed to repo as success.
So I read that "docker image inspect repo/myimage:1
" returns a result "1" or "0". if 0 success.
How can I add this step and check in pipeline? If docker inspect returns 1, build pipeline should fail.
3
Answers
You can add a bash task in devops, after
docker inspect
related command, check return code if it’s 1(non-zero), fail the task with logging commandecho "##vso[task.complete result=Failed;]Failed"
Another option is to use the failOnStderr
This parameter will fail the step if anything is written to the Standard Error (Stderr). If docker image inspect command fails, it writes the error to Stderr, so the step will fail.
Run the docker image inspect command and store its result in a variable.
Use a custom script step to evaluate the variable and control the pipeline outcome based on its value.
The first script step runs the docker image inspect command and sets the result in the DockerResult variable.
This way, the pipeline will only continue with the deploy job if the docker image inspect command succeeds. If it fails, the pipeline will stop and be marked as failed