How do i trigger a pipeline from another pipeline

simon February 7, 2025

SO i have the pipeline below, Which run fine when i commit to master but i want it to run a separate pipeline after master is tagged. 

Which it does not...  no erros or anything, I have read that this might not be possible? any advice on doing this?

image: node:18

clone:
  depth: full

definitions:
  steps:
    - step: &tag-repo
        name: Tag with latest version number
        script:
          - npm version patch -m "[skip ci] bumped the version"
          - VERSION=$(node -e "console.log(require('./package.json').version);") 
          - git push origin master    # Push the changes to the master branch
          - git push origin --tags
          - cat package.json
    - step: &get-version
        name: Determine latest build number
        script:
          - VERSION=$(node -e "console.log(require('./package.json').version);")
          - ls -ltr
          - cat package.json
          
pipelines:
  branches:
    master:
      - step: *tag-repo
      
  tags:
    "*":
      - step: *get-version

 

1 answer

1 accepted

2 votes
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 10, 2025

Hi @simon,

Does the following command from your bitbucket-pipelines.yml file add a commit and then a tag to this commit?

- npm version patch -m "[skip ci] bumped the version"

And do you expect the tags pipeline to run for this tag you added and pushed during the &tag-repo step?

If so, I believe the reason that the tags pipeline is not triggered is because of the [skip ci] text in the commit message. This will make pipelines skip any automated builds on this commit (including the tags pipeline).

I wouldn't recommend removing the [skip ci] text from the commit message, otherwise the master branch pipeline will get triggered as well when you push this commit, and then you'll have an endless loop of builds on master branch. There is, however, another way to trigger the tags pipeline.

 

You can use the pipe trigger-pipeline in your &tag-repo step, and this can trigger the tags pipeline despite the [skip ci] text.

If we assume that the variable VERSION is the one that has as value the name of the tag you just added, you can adjust the step as follows:

- step: &tag-repo
name: Tag with latest version number
script:
- npm version patch -m "[skip ci] bumped the version"
- VERSION=$(node -e "console.log(require('./package.json').version);")
- git push origin master # Push the changes to the master branch
- git push origin --tags
- cat package.json
- pipe: atlassian/trigger-pipeline:5.8.1
variables:
BITBUCKET_ACCESS_TOKEN: $BITBUCKET_ACCESS_TOKEN
REPOSITORY: '$BITBUCKET_REPO_SLUG'
REF_TYPE: 'tag'
REF_NAME: '$VERSION'

 

If the variable VERSION (that you define in the second line of the script) doesn't have as value the name of the tag you added, you can look into retrieving the tag name during the step and storing it in another variable that you can use in the pipe.

The variable BITBUCKET_REPO_SLUG is a default variable in Pipelines (no need to create it) and it has as value the repo slug of the repo where the build is currently running.

You will need to create the variable BITBUCKET_ACCESS_TOKEN.

  • First, you'll need to generate an access token from Repository settings > Access tokens and ensure it has Pipelines Write and Repositories Read permissions.
  • Then, from Repository settings > section Pipelines - option Variables, you can create a variable with the name BITBUCKET_ACCESS_TOKEN and store in it the value of the access token you generated in the previous step.

    You'll need to have admin permissions to the repo in order to generate an access token and create a variable.

Please feel free to let me know if this works for you and if you have any questions!

Kind regards,
Theodora

simon February 10, 2025

Thank you Theodora, 
one question is there a Access token that i can reuse from the pipeline instead of creating a. new one ?

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 10, 2025

You're very welcome, Simon.

No, I'm afraid that there is no available access token that can be used for the pipe. It is necessary to create a new one.

It is also possible to use username and app password for authentication (this is mentioned in the pipe's README), however I recommended the access token for a more scoped approach (the username and app password would grant access to all repos an account has access to).

simon February 11, 2025

@Theodora Boudale 

I i already have a bot and appsecret for that bot can i use that as the auth for the pipeline trigger. ?

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 12, 2025

Hi @simon,

Is that bot a separate Bitbucket account? If so, you could use its username and app password (ensure the app password has Pipelines Write and Repositories Read permissions), but the account also needs to have write permission to the repo in order to trigger a pipelines build with its credentials.

Kind regards,
Theodora

Suggest an answer

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

Atlassian Community Events