Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

mikeym88
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 5, 2022

 

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
Atlassian Team members are employees working across the company in a wide variety of roles.
March 7, 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

mikeym88
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 7, 2022

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
Atlassian Team members are employees working across the company in a wide variety of roles.
March 8, 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
AUG Leaders

Atlassian Community Events