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

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\$')
```


Answers:
author: Mark C
body: Hi [@mikeym88](/t5/user/viewprofilepage/user-id/368129)

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

comments: author: mikeym88
body: Hi [@Mark C](/t5/user/viewprofilepage/user-id/1210823) 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"?


author: Mark C
body: Hi [@mikeym88](/t5/user/viewprofilepage/user-id/368129)  

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/bashgrep --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
```

<br />

Let me know how it goes.  

Regards,  
Mark C  


Tags: azure

bitbucket-cloud

bitbucket-pipelines

cloud

flask