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

can we run pipes in a bash script ?

Irfan Nazer
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 18, 2023

I have multiple steps that should be run on different conditions, and every step should run on the same deployment, so instead of using the inbuild condition which the bitbucket pipeline provided I've started checking within the scripts

 

- step: &DeployUI
        oidc: true
        size: 2x
        name: Deploy UI
        caches:
          - node
        script:
          - |
            if git diff-tree --no-commit-id --name-only -r HEAD | grep -q "src" || git diff-tree --no-commit-id --name-only -r HEAD | grep -q "public"; then
            npm install
            CI=false npm run build
            pipe: atlassian/aws-s3-deploy:1.2.0
                variables:
                  AWS_DEFAULT_REGION: $REGION
                  AWS_OIDC_ROLE_ARN: "arn:aws:iam::$ACC_ID:role/Admin"
                  S3_BUCKET: $content_bucket
                  LOCAL_PATH: "build"
            pipe: atlassian/aws-cloudfront-invalidate:0.7.0
                variables:
                  AWS_DEFAULT_REGION: $REGION
                  AWS_OIDC_ROLE_ARN: "arn:aws:iam::$ACC_ID:role/Admin"
                  DISTRIBUTION_ID: $cloudfront_dist_id
but its not identifying this pipe what should I do

1 answer

2 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 19, 2023

Hello @Irfan Nazer and welcome to the Community!

Since pipes are a Bitbucket cloud's feature, their definition must be placed within the step's script YML attributes for it to be correctly identified by pipelines.

One route you could take for putting the conditions in the step while still being able to execute the pipe is to force the exit of the step if the condition is/is not met, as in the following example : 

script:
  - if [[ ! $CONDITION ]]; then exit 0 ; fi #if $CONDITION is not met, exit the step and goes to next step
- npm install
- pipe: atlassian/email-notify:0.11.0 variables: USERNAME: 'myemail@example.com' PASSWORD: $PASSWORD FROM: 'myemail@example.com' TO: 'example@example.com' HOST: 'smtp.gmail.com' PORT: 587 SUBJECT: 'Bitbucket Pipe Notification for your-bitbucket-brunch' DEBUG: true

In the above example, if the boolean condition $CONDITION is not met, we will force the completion of the step with exit 0 (so the step will be completed with Success status), which will make the pipelines go to the next step in the build, if any, or complete the pipeline if there are no remaining steps.

On the other hand, if the boolean condition $CONDITION is true, it will continue the execution of the next commands in the step's script, which includes the npm install and the pipe execution.

Hope that helps! Let me know in case you have any questions.

Thank you, @Irfan Nazer !

Patrik S

Suggest an answer

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

Atlassian Community Events