azure-pipelines-agent: Cannot call git tag/push in yaml build
- powershell: |
Write-Host "git tag $env:tag"
git tag $env:tag
Write-Host "git push origin $env:tag"
git push origin $env:tag
displayName: Git Tag
workingDirectory: $(Build.SourcesDirectory)
env:
tag: '$(PACKAGE_VERSION)'
SYSTEM_ACCESSTOKEN: $(system.accesstoken)
ignoreLASTEXITCODE: false
errorActionPreference: Stop
failOnStderr: true
This command freezes forever no matter what permissions I add. I’m able to call the same command from the UI build and it works without any issues, this is only a problem in yaml builds.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 22 (6 by maintainers)
For the sake of completeness: We had a similar issue with git failing. Here is how re resolved it! 🎉
Then, we did not have to pass the bearer token using
git -c ....
as described above. Rather, we just had to add a taskcheckout
withpersistCretentials:true
.Finally, there was one more important step: We had a powershell inline script which was essentially calling
this ALWAYS failed with the error code 1 as it is described above in this thread. The only way we could get rid of this error was to split those comands into two separate powershell scripts
So for you guys, here is the essential parts of our yaml file:
Just for reference, there’s another way of doing this…
The
persistCredentials
allows the token to be automatically passed to other git commands. Note the assignment ofworkingDirectory
, otherwise I had an error that the location was not a git repository.For an annotated tag rather than lightweight tag, the syntax would look like this…
To get a user/date against it you need to set the user name/email as well e.g.
For this to work, the Project Collection Build Server account (not the Project Build Service Accounts group) needs to be allocated the Contribute permission for the Repositories
failOnStderr: false
fixed the issueThanks for all the help
@AceHack it’s available in ENV for yaml build for now, we are working on repository checkout option for preserver git credential, for now, i guess you need to run
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" tag MyTag
UPDATE: Redirecting git stderr to stdout is error-prone because it hides errors and progress, and modifies output of git commands. It’s better to rely on failOnStderr like others pointed out.
OK. Apparently git writes progress to stderr… (just test/google it for more info)
But
failOnStderr: false
is like trying to kill a fly with a bazooka.And there is an environment variable called GIT_REDIRECT_STDERR.
You could add it in your powershell:
Or in the variables section of your pipeline (which also injects it in the environment):
Thanks for helpful conversation. Found this on https://stackoverflow.com/a/58492632/880524
@TingluoHuang FYI, I’ve included my command as I did previously and you can see I’m already doing what you suggested.
Also as I’ve stated earlier I’ve tried every combination of adding
-c http.extraheader="AUTHORIZATION: bearer $env:SYSTEM_ACCESSTOKEN"
, only on the tag, only on the push, on both the tag and push and on neither the tag nor push. They all fail in some way.I will try turning off failOnStderr and report back.
Thanks.