Joe
Joe

Reputation: 6796

Unable to apply Git Tag in Azure pipeline cloud build. Works on local agent though

Despite following the Microsoft instructions here on how to give a YAML pipeline the ability to run Git commands in a script, I can't seem to make mine properly apply a Git tag to the repo when I build in the cloud. It works on the local hosted agent though.

Can anyone spot what I'm doing wrong?

I keep getting this error:

2020-07-28T03:04:25.7818359Z + git push origin  v1.0.6253
2020-07-28T03:04:25.7818711Z + ~~~~~~~~~~~~~~~~~~~~~~~~~~
2020-07-28T03:04:25.7821133Z     + CategoryInfo          : NotSpecified: (To https://dev....ftware/_git/Sdk:String) [], RemoteException
2020-07-28T03:04:25.7822040Z     + FullyQualifiedErrorId : NativeCommandError
2020-07-28T03:04:25.7822281Z  
2020-07-28T03:04:25.9298244Z ##[error]PowerShell exited with code '1'.

My YAML step looks like this:

- task: PowerShell@2
  displayName: 'Tag the build with v$(fullVersion)'
  inputs:
    targetType: 'inline'
    script: |
      cd $(sdkFolder)
      git config user.email "[email protected]"
      git config user.name "Build Script"
      git tag -a v$(fullVersion) -m "Nightly Build"
      git push origin v$(fullVersion)

(Note: I used my actual name and address in the actual script)

When I say I "followed the Microsoft instructions", I mean I gave my repo's "Project Collection Build Service" user the rights to do the following (it already had the other rights)

Contribute
Create branch
Create tag

Here's what that user's permissions look like:

enter image description here

And I was careful to apply persistCredentials: true to the repo checkout

steps:
- checkout: git://Software/Sdk
  persistCredentials: true

Upvotes: 1

Views: 297

Answers (1)

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41545

The operation is succeeded, this is not a "real" error, it's because git push is sending output to stderr, not stdout so PowerShell thinks it's an error.

How to prevent it?

There are several options but the shortest it's just to add --porcelain to the git push:

git push origin v$(fullVersion) --porcelain

Upvotes: 2

Related Questions