Is it possible to call a step from an anchor with after-script? I cannot see any related article that is doing it as of the moment.
What we are trying to accomplish is to create an anchor that also calls another anchor whenever that build fails. Another challenge is when the step that we are trying to assess uses different image from what the after-script is trying to do.
Thanks
Hi @Bitwise DEVS,
It is not possible to call a step from the after-script. Just to give you some context, for each step in your yml file, a Docker container starts based on the Docker image you have specified in your yml file. The repo is cloned in that container and then the commands of that step's script are executed. The commands of the after-script are executed in the same Docker container, and then that container gets destroyed. So, the after-script can include one or multiple commands.
If certain tools you need are not available, you can install them during the step by adding the necessary commands in your yml file. Another option would be to build your own custom image with the tools you need, push it to Docker Hub or another registry, and then use this custom image as a build container. You can find some resources about this here:
Kind regards,
Theodora
If we have `image` in step level and top level which one is being used?
Can we use `pipe` and `image` at the same time? Specifically use `pipe` in `after-script`?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bitwise DEVS,
If we have `image` in step level and top level which one is being used?
The image on the step level is going to be used. The top one will be used for steps that don't have an image on the step level (if any).
Can we use `pipe` and `image` at the same time? Specifically use `pipe` in `after-script`?
Yes, the two options are not related to each other.
The image specifies which Docker image is going to be used for the build container where the step runs.
A pipe can be used either in the script or in the after-script of a step. The pipe will start a separate Docker container based on the pipe's Docker image.
Please feel free to let me know if you have any other questions.
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is there a sample how to use pipe in after-script? Trying to write it this way but haven't actually run it.
- step: &create-keys # YAML anchor for reusable step https://support.atlassian.com/bitbucket-cloud/docs/yaml-anchors/
name: Create Keystore file
script:
- mkdir keys # Create new directory
- echo $DEBUG_KEYSTORE_FILE_BASE64 | base64 -d > keys/$DEBUG_KEYSTORE_FILE # Decode Base64 then use DEBUG_KEYSTORE_FILE as file name defined in repository variable
artifacts: # Keep these artifacts for subsequent pipeline steps
- keys/** # Artifacts are files that are produced by a step https://support.atlassian.com/bitbucket-cloud/docs/use-artifacts-in-steps/
after-script:
- if [[ $BITBUCKET_EXIT_CODE -eq 0 ]]; then exit 0; else echo "Step failed, generating build status badge"; fi
- pipe: atlassian/bitbucket-upload-file:0.1.2 # Deploy your artifacts using the bitbucket-upload-file pipe approach https://support.atlassian.com/bitbucket-cloud/docs/deploy-build-artifacts-to-bitbucket-downloads/ or https://bitbucket.org/atlassian/bitbucket-upload-file/src/master/
variables: # Bitbucket app passwords allow you to deploy an artifact that has been produced by your pipeline to Bitbucket Downloads
BITBUCKET_USERNAME: $BITBUCKET_USERNAME
BITBUCKET_APP_PASSWORD: $BUILD_STATUS_BADGE_PASSWORD
FILENAME: 'status.svg' # The file to be uploaded on Bitbucket Downloads
Currently the JetBrain's IDE is marking it error Invalid child element in a block mapping not sure if it is false positive.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bitwise DEVS,
The pipe is used in the after-script the same way it is used in the script.
Please ensure that
Your IDE may still show an error, but the yml should work with this indentation.
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.