It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to add datetime to custom VERSION_LABEL in pipeline pipes Edited

How can I let pipelines resolve the current datetime for a VERSION_LABEL?

Cuurentlly I have this but its only adding the string "YYY-mm-dd_HHMMSS" to my resulting version tag:

 

VERSION_LABEL: "${APPLICATION_ENVIRONMENT}_YYYY-mm-dd_HHMMSS_${BITBUCKET_BUILD_NUMBER}"

1 answer

0 votes

Hi Sascha,

Just to confirm (I'm assume from the syntax), this is for a Pipe?

Pipelines supports environment variables as parameters for pipes. You should be able to use variables with the following configuration:

VERSION_LABEL: $APPLICATION_ENVIRONMENT"_YYYY-mm-dd_HHMMSS_"$BITBUCKET_BUILD_NUMBER

Thanks,

Phil

Hi Phil,

 

thanks for your response. Yes your are right: I am talking about Pipes.

Unfortunately that doesnt work. Tested it right ahead and its still not resolving the date time pattern. It does resolve the env variables though (as expected). With the configuration you suggested I get this result (again):

"VersionLabel": "myresolvedappenvname_YYYY-mm-dd_HHMMSS_109",

Seems Pipes is not capable of resolving those patterns yet.

Sascha

Oh sorry, I misinterpreted what you wanted.

The value you provide here is passed into a Docker shell command, so standard Bash string substitution should work here.

e.g.

See LOCAL_PATH. It will be set as "hello-world"

pipelines:
default:
- step:
script:
- mkdir hello-world
- pipe: atlassian/aws-s3-deploy:0.2.1
variables:
AWS_ACCESS_KEY_ID: $ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: "us-east-1"
S3_BUCKET: "my-bucket-name"
LOCAL_PATH: '$(echo "hello-world")' # This line here.

You should be able to get what you want with roughly:

VERSION_LABEL: '$APPLICATION_ENVIRONMENT"_"$(date +%Y%m%d_%H%M%S)"_"$BITBUCKET_BUILD_NUMBER'

Obviously it's not the nicest looking config, so you could instead create the variable like this:

pipelines:
default:
- step:
script:
- export LABEL=$APPLICATION_ENVIRONMENT"_"$(date +%Y%m%d_%H%M%S)"_"$BITBUCKET_BUILD_NUMBER
- pipe:
...
VERSION_LABEL: $LABEL

Or something along those lines. There might be some syntax errors in those examples. But hopefully you see what I mean.

Hi Phil.

Thanks for your response. It works. finally ended up with this:

 

- step:
name: Development EB-Deplyoment
deployment: test
script:
- pipe: atlassian/aws-elasticbeanstalk-deploy:0.2.1
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
APPLICATION_NAME: $APPLICATION_NAME
VERSION_LABEL: $APPLICATION_ENVIRONMENT_$(date +%Y-%m-%d_%H:%M:%S)_$BITBUCKET_BUILD_NUMBER
ENVIRONMENT_NAME: $APPLICATION_ENVIRONMENT
ZIP_FILE: "artifact.zip"
Like Deleted user likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket Pipelines

What We Learned When We Researched Open Source Vulnerabilities in 7 Popular Coding Languages

...hey are a part of us, shaping how we interact with the world around us. The same holds true for programming languages when we think about how different kinds of vulnerabilities raise their heads in t...

1,038 views 0 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you