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\$')
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"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.