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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,677
Community Members
 
Community Events
176
Community Groups

Bit Bucket Pipelines: can't modify files as a build step?

Edited

 

I am using trying to deploy a Python Flask app to an Azure App Service using BitBucket Pipelines. I am also trying to included the latest commit Id when deploying. For this I am using Git Attributes.

In my base.html file, I have added "$Format:Version: %h$" to a span element. In my .gitattributes file, I have added "*.html text export-subst" as a entry (on its own line).
When I run `git archive` locally, it works as expected: "$Format:Version: %h$" is replaced with "Version: xxxxxxx". But when I use the same `git archive` command in my bitbucket-pipelines.yml, that format is not replaced at all. What Am I doing wrong?

bitbucket-pipelines.yml

image: atlassian/default-image:3

pipelines:
branches:
dev:
- step:
name: "Build"
script:
- git archive --format zip -v --worktree-attributes -o ./app-$BITBUCKET_BUILD_NUMBER.zip HEAD
artifacts:
- app-*.zip
- step:
name: 'Deployment to Dev'
deployment: test
script:
- pipe: atlassian/azure-web-apps-deploy:1.0.1
variables:
AZURE_APP_ID: $AZURE_APP_ID
AZURE_PASSWORD: $AZURE_PASSWORD
AZURE_TENANT_ID: $AZURE_TENANT_ID
AZURE_RESOURCE_GROUP: $AZURE_RESOURCE_GROUP
AZURE_APP_NAME: 'AppServiceName'
ZIP_FILE: 'app-$BITBUCKET_BUILD_NUMBER.zip'

I tried another solution creating a shell script (`build.sh`) and using `sed` to replace the `$Format:Version: %h$` string. That does not work either.

The sed commands I used:

sed -i "s/\$Format:Version: %h\\$/Version\: ${BITBUCKET_COMMIT: -7}/g" $(grep --include \*.html -l -r . -e '\$Format:Version: %h\$')

 

1 answer

0 votes
Mark C Atlassian Team Mar 07, 2022

Hi @mikeym88

Thank you for reaching out to the community.

For us to see if it will work within the same container, would it be possible for you to use a single step instead?

For the sed command you used, could you possibly share it here as well?

Thanks and looking forward to your response.

Regards,
Mark C

Hi @Mark C I've updated the questions with the sed command. As for combining the steps, would I just move "git archive ..." to the scripts of "Deployment to Dev"?

Mark C Atlassian Team Mar 08, 2022

Hi @mikeym88

Thanks for providing the sed command you used.

For the steps, yes, you can combine by moving the git archive command to the "Deployment to Dev" step.

For the sed command alternative, would it be possible for you to try the bash script below?

Create a file (
file.sh) with the command below:

#!/bin/bash

grep --include \*.html -l -r . -e '\$Format:Version: %h\$' | xargs -r sed -i "s/\$Format:Version: %h\\$/Version\: ${BITBUCKET_COMMIT: -7}/g"

Use it in your step like below:

chmod +x file.sh
./file.sh


Let me know how it goes.

Regards,
Mark C

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events