Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Using Step or Anchor with After-Script

Bitwise DEVS February 27, 2024

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.

Screenshot 2024-02-28 at 8.00.58 AM.png

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

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 4, 2024

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

Bitwise DEVS March 4, 2024

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`?

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 5, 2024

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

Bitwise DEVS March 6, 2024

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.

Screenshot 2024-03-07 at 6.35.01 AM.png

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 8, 2024

Hi @Bitwise DEVS,

The pipe is used in the after-script the same way it is used in the script.

Please ensure that

  • variables: has 2 spaces indentation from the previous level, - pipe: ...
  • BITBUCKET_USERNAME, BITBUCKET_APP_PASSWORD, and FILENAME have 2 spaces indentation from the previous level, variables:

Your IDE may still show an error, but the yml should work with this indentation.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events