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

Bitbucket Pipeline: How to keep artifacts for next steps even if current is skipped?

Asif Baig September 10, 2023

I have pipeline setup that looks similar to that of the pseudo code pasted below.

I am facing a problem with availability of `artifacts.txt` file in the Third step if in-case the Second step is skipped, which is a valid scenario for us.

But looks like whenever the second step is skipped, the artifacts file are not available for third step as well.

How can we get this enabled? Because as per the official documentation:

Artifacts that are created in a step are available to all the following steps.

But it doesn't mentioned what happens if one of the steps in between is skipped, do we have a way around this?

pipelines:
branches:
develop:
- step:
name: Generate Artifacts
script:
- echo "Generate Some Artifact" > artifacts.txt
artifacts:
- artifacts.txt
- step:
name: Optional Build Step
condition:
changesets:
includePaths:
- "build_dir/**"
script:
- echo "Only build if changes made in specific directory"
- step:
name: Mandatory Final Step
script:
- echo "Use artifacts.txt generated in step 1"
- DATA=$(cat artifacts.txt)
- echo "Some final steps of build"

 

1 answer

1 accepted

1 vote
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 11, 2023

Hi Asif and welcome to the community!

I ran a build using the bitbucket-pipelines.yml file you provided in your post but I am unable to reproduce this error. The file artifacts.txt is available in the third step of my build regardless of whether the second step runs or not.

I would suggest the following:

  • On Bitbucket website, open a build with the issue you reported, select the first step, and then select Build teardown in the build log. Is there a message there "Successfully uploaded artifact" or is there any error about the artifact upload?

  • On the same build, select the third step and then select Build setup in the build log. Do you see a message there about artifacts being downloaded and extracted?

  • You can add the command ls -lah in the third step's script to see if the artifact file is listed.

If you still cannot figure it out, you can post the build URL in the support ticket you created and the engineer working on your ticket can help with troubleshooting.

Please feel free to reach out if you have any questions!

Kind regards,
Theodora

Asif Baig September 12, 2023

Thank you @Theodora Boudale !

Your comment made me take another look at the code and failed builds, realized that there was an exit 0 line left over in an IF-ELSE block just above the code where the build is supposed to generate the artifact file.

The step was exiting with success status but without generating the artifact file itself!

Thank you for your suggestions!

- Asif

Like Sabine Mayer likes this
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 12, 2023

Thank you for the update Asif, it's good to hear that you figured this out!

Please feel free to reach out if you ever need anything else!

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events