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.
I did not test this on Bitbucket but I can imagine it works this way:
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 "$").
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.