Home > Software design >  Azure Devops Build: trying to get the last changes when PR is merged
Azure Devops Build: trying to get the last changes when PR is merged

Time:11-10

Requirement

Whenever a feature needs to be deployed to en environment a PR is created. To complete this PR some builds need to be validated first. Only when this is done we can complete the PR.

After the PR is completed and merged. A Build is triggered on the target (environment) branch. This will deploy the changes.

Issue

After to completion and merge of the PR build is triggered that will take the last changes through git diff and deploy it. I take the last changes through this command

$ git diff --name-only --diff-filter=d HEAD^ HEAD

Whenever this is executed I receive the following error.

fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
##[error]Bash exited with code '128'.

But after that I trigger the build manually and then the git diff works and the deploy happens smoothly.

Question

Why does it give an error when it is automatically triggered through a commit on the target (environment) branch, and why does it work when I trigger it manually?

These are the commands I already tried, without success $ git log -1 --name-only --oneline OR $ git diff --name-only --diff-filter=d HEAD^ HEAD OR $ git diff --name-only --diff-filter= @~..@

CodePudding user response:

New pipelines created after the September 2022 Azure DevOps sprint 209 update have Shallow fetch enabled by default and configured with a depth of 1. If your repository is large, this option might make your build pipeline more efficient.

You can configure the Shallow fetch setting from the properties of the Get sources task in your pipeline. Like increase the depth to 5. Refer to enter image description here

  • Related