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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How do I modify variables in a build

Edited

I'm trying use the variable BITBUCKET_BRANCH to define a filename, but the slash is causing us issues. Here's a sample YAML

pipelines:
branches:
feature/*:
- step:
name: Build javascript
image: node:12.16.3
caches:
- node
script:
- apt-get update && apt-get install --yes zip
- npm install
- npx ng build
- zip -r ${BITBUCKET_BRANCH}.zip dist
- pipe: atlassian/bitbucket-upload-file:0.1.4
variables:
BITBUCKET_USERNAME: $NAME
BITBUCKET_APP_PASSWORD: $PASSWORD
FILENAME: "${BITBUCKET_BRANCH}.zip"

 

How can I modify the BITBUCKET_BRANCH variable to remove non-alphanumeric characters? For example changing from: feature/bitbucket-ci --> featurebitbucketci.

2 answers

I did not test this on Bitbucket but I can imagine it works this way:

  • Define a new variable that contains the filename in the form you prefer
  • Use it in your step-script (e.g. for creating the zip)
  • Export it so that mapping to the variable table of the Pipe works (?)

Example (tested to work with the node:12.16.3 image):

script:
- PACKAGE_FILE="${BITBUCKET_BRANCH//\//-}.zip" # replace all slashes with dashes
  - zip -r ${PACKAGE_FILE} dist
- export PACKAGE_FILE
- pipe: atlassian/bitbucket-upload-file:0.1.4
variables:
BITBUCKET_USERNAME: $NAME
BITBUCKET_APP_PASSWORD: $PASSWORD
FILENAME: $PACKAGE_FILE

 Discussion:

It might already work like this. Fine. Here is some more context of why I suggest this:

It is my understanding that the variables property of a pipe needs to contain strings. These are passed to the docker run command that runs the pipe image as --env NAME=value command line options and arguments.

This command runs in the same shell script as the other script lines. Therefore technically the export should not be necessary. Additionally it should not be necessary to use the plain string $PACKAGE_FILE for the FILENAME: property. However from your report I'm not entirely sure if this is stable and as written I didn't test this on Bitbucket (and the local Bitbucket Pipeline runner I'm using does not have full pipe support [yet], so local testing is limited to some degree).

Therefore the extra script line to export the $PACKAGE_FILE variable and overall to create an extra variable so that the pipe.variables table has it in a simple manner (just $PACKAGE_FILE, just the variable name prefixed with the dollar sign "$").

0 votes

Hi @Jacob Craig ,

Thank you for your question!

You could create a new variable:

- ARTIFACT_FILENAME=$(echo $BITBUCKET_BRANCH | sed "s/[^a-zA-Z0-9]//g")
- zip -r ${ARTIFACT_FILENAME}.zip dist

That part was easy enough to do, the question was how to send that into the pipe.

FILENAME: "${BITBUCKET_BRANCH}.zip" 

I thought those were unfurled at the beginning of the run.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence Cloud

🎨 Add some visual life to your templates

Hi Atlassian Community, My name is Avni Barman, and I am a Product Manager on the Confluence Cloud team. Based on feedback from you, we are giving admins more power to create templates that a...

61 views 1 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you