I'm trying to create a custom bitbucket pipeline which has 2 inputs - version and target environment that deploys a specific version of the app(based on git tags) to different environments.
image: python:3.12
clone:
enabled: true
depth: full
lfs: false
definitions:
caches:
sonar: ~/.sonar/cache
pipelines:
custom:
pipelineName:
- variables:
#my variable definition here for VERSION.
- step:
name: Checkout version
script:
- git describe --tags #outputs the most recent tag - v1.2.0
- echo "Deploying version ${VERSION} to $Environment environment..."
- git checkout tags/$VERSION
- git describe --tags #outputs the tag I want - v1.0.0
- step:
script:
- git describe --tags #again back to most recent tag v1.2.0
But the problem is if I checkout tag (say v1.0.0) in step 1, it's back to the most recent tags in all the subsequent steps. Like I never did the checkout. How can I stash or persist the git checkout in 1 step so that it stays there in the following step?
Also I wanted to check if I'll be able to add additional script commands to a predefined step.
Say I have a predefined step called "deploy-images". Now in my pipeline, will I be able to add bash script before or after I run that predefined step, so that all of this is in 1 single step.
steps:
- step: &deploy-images
script: #few bash statements here
pipelines:
branches:
develop:
- step:
script: git checkout tags/$VERSION
*deploy-images
script: git describe --tags
Thanks in advance.
Welcome to the community.
Could you try to push the tag and see if persists in the next step?
I suspect it is not in the remote repo, hence, it hasn't changed.
About adding steps to your Pipelines configuration, you have the following options:
Regards,
Mark C
Yes, I did the below.
- step:
name: Checkout version
script:
- git describe --tags #v1.1.0
- git tag testTag
- git push --tag
- step:
script:
- git fetch --tags
- git tag #outputs - testTag, v1.0.0, v1.1.0
After script would need to be added at the step definition stage then right?
Will I be able to call a defined step and add after script to it while defining pipelines. For cases where I'm using the same defined step but need different after scripts based on the pipeline.
steps:
- step: &deploy-images
script: #few bash statements here
pipelines:
branches:
develop:
- step:
script: git checkout tags/$VERSION
*deploy-images
script: git describe --tags
branch2:
- step: *deploy-images
I have a defined step here called deploy-images. I need to to run few scripts before and after, in only the develop branch-pipeline there. And I don't want to run the before and after scripts on branch2 pipeline.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, the after-script will need to be added at the end of a step.
As far as I can tell, it seems that you're looking for a way to execute separate scripts and a step in between.
Unfortunately, that is not possible at the moment, you can only run one script in a step.
You can consider trying to use multiple steps instead or using stages.
Regards,
Mark C
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.