At the moment, I have pipelines that run during a pull request and one when we merge to main. I want to be able to share data between them for version control but I am not able to do so. Just for more context, see example below:
pipelines:
pull-requests:
develop*:
-step: export dummy_data=1
branch:
main:
script:
- echo "$dummy_data"
I tried a suggestions in one of the forums that recommended to use the trigger pipeline( if you have any other suggestions please let me know.
Current the trigger pipeline is as follows(i include the promote pipe in the pull request pipe.
step: &promote
name: Promote
script:
- source version.env
- BB_TOKEN=secret
- pipe: atlassian/trigger-pipeline:5.8.1
variables:
BITBUCKET_ACCESS_TOKEN: $BB_TOKEN
REPOSITORY: <name-of-repo>
REF_TYPE: 'branch'
REF_NAME: develop_branch
PIPELINE_VARIABLES: >
[
{
"key": "dummy_data",
"value": "1"
}
]
WAIT: 'true'
Every time I run with this step I get the following error, I am not sure what I am setting wrongly.
✖ Error: {"error": {"message": "Bad request", "detail": "Requested selector is not found in bitbucket-pipelines.yml.", "data": {"key": "result-service.pipeline.selector-not-found", "arguments": {}}}}
Hi and welcome to the community!
The variable PIPELINE_VARIABLES in the pipe is only available for custom pipelines. You cannot use it with any other type of pipeline.
You can use the pipe atlassian/trigger-pipeline to trigger a custom pipeline for the main branch while the pull-requests build is running, and also pass data to that custom pipeline. Please keep in mind that this build on main won't get triggered when there is a merge on main, it will get triggered when you call the pipe during the pull-requests build.
If you want to do this, you can do it the following way:
In the bitbucket-pipelines.yml file define a custom pipeline with variables. You can check the documentation here:
This is an example:
pipelines:
custom:
my-custom-pipeline:
- variables:
- name: dummy_data
- step:
script:
- echo "This is the dummy data: $dummy_data"
You can remove the definition for the main branch pipeline if you don't intend to run builds on main automatically on every push or merge.
It's important that the definition is present in the bitbucket-pipelines.yml file of the main branch, if you want to trigger this custom pipeline on main.
Then, in the bitbucket-pipelines.yml file of any develop* branches, you can add the atlassian/trigger-pipeline pipe so that it triggers the custom pipeline on the main branch as follows:
script:
- pipe: atlassian/trigger-pipeline:5.8.1
variables:
BITBUCKET_ACCESS_TOKEN: $BB_TOKEN
REPOSITORY: '<name-of-repo>'
REF_TYPE: 'branch'
REF_NAME: 'main'
CUSTOM_PIPELINE_NAME: 'my-custom-pipeline'
PIPELINE_VARIABLES: >
[{
"key": "dummy_data",
"value": "some-value-here"
}]
WAIT: 'true'
The value of the variable CUSTOM_PIPELINE_NAME needs to be the same as the name of the custom pipeline you want to trigger. I have highlighted both in bold.
In the variable PIPELINE_VARIABLES, the key of the variable needs to be the same as the name of the custom pipeline's variable. I have also highlighted these in bold.
If this solution doesn't work for you because you want to trigger a pipeline on main only when there is a push to main (and not during the pull-requests build), you can look into saving the data from the pull-requests build into a file that you store externally (e.g. in the Downloads section of the Bitbucket repo) and then have the main pipeline download and read this file. You can use our APIs for uploading and downloading a file from the Downloads of the repo:
With regards to the access token, it is certainly possible to store it as a variable. You need to have admin permissions in the repo to do that.
Please feel free to let me know how it goes and if you have any questions!
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.