1
votes

I have created a powershell script that is ran as the first step in my build definition that gets the latest code and tags the branch as well as execute GitVersion.exe /updateassemblyinfo.

The problem I am having now is that the TFS build definition creates a detached head (branch?) and whenever I try to do a git checkout master, it displays as an error in the output.

2017-12-20T02:59:28.3245551Z Running 'git clean -fdx' on D:\agent_work\87\s.

2017-12-20T02:59:28.3713306Z Running 'git reset --hard HEAD' on D:\agent_work\87\s.

2017-12-20T02:59:28.4337848Z HEAD is now at 00382dd Dummy change2

2017-12-20T02:59:28.4337848Z Starting fetch...

2017-12-20T02:59:28.6209313Z Checking out 00382dd7601ab49b146240338e3f89e70aae2ece to D:\agent_work\87\s

2017-12-20T02:59:28.6677321Z Checked out branch refs/heads/master for repository ABN at commit 00382dd7601ab49b146240338e3f89e70aae2ece

2017-12-20T02:59:28.6677321Z commit=00382dd7601ab49b146240338e3f89e70aae2ece

2017-12-20T02:59:28.6677321Z Leaving TfsGitSourceProvider.PrepareRepositoryAsync

2017-12-20T02:59:28.8081365Z Running tasks

2017-12-20T02:59:28.8237446Z Starting task: Powershell: Build.ps1

2017-12-20T02:59:28.8549329Z . 'D:\agent_work\87\s\Build.ps1'

2017-12-20T02:59:28.8705393Z C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "try { [System.Security.Cryptography.ProtectedData] | Out-Null } catch { Write-Verbose 'Adding assemly: System.Security' ; Add-Type -AssemblyName 'System.Security' ; [System.Security.Cryptography.ProtectedData] | Out-Null } ; Invoke-Expression -Command ([System.Text.Encoding]::UTF8.GetString([System.Security.Cryptography.ProtectedData]::Unprotect([System.Convert]::FromBase64String('AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAArGybdmeqjkeRrRCzDg34RQAAAAACAAAAAAADZgAAwAAAABAAAAARQNIZ8ZSSCdvKkC9ig9FQAAAAAASAAACgAAAAEAAAAA05pop9sZqolQMnXBaYCcEoAAAAJWiIi4dluseSGAh6baRpqKRCAen5vNpoXE1rso5mC6ionSeRDREhsRQAAAAulpIkem7g6hB4in0HmeadOg7cOw=='), [System.Convert]::FromBase64String('XRQnTZZ+4fqW37oX7nUNSA=='), [System.Security.Cryptography.DataProtectionScope]::CurrentUser))) ; if (!(Test-Path -LiteralPath variable:\LastExitCode)) { Write-Verbose 'Last exit code is not set.' } else { Write-Verbose ('$LastExitCode: {0}' -f $LastExitCode) ; exit $LastExitCode }"

2017-12-20T02:59:28.8705393Z Executing the following powershell script. (workingFolder = D:\agent_work\87\s)

2017-12-20T02:59:28.8705393Z D:\agent_work\87\s\Build.ps1

2017-12-20T02:59:30.1653526Z Your branch is up-to-date with 'origin/master'.

2017-12-20T02:59:30.2277683Z ##[error]Switched to branch 'master'

2017-12-20T02:59:30.2277683Z Already up-to-date.

2017-12-20T02:59:30.2277683Z Success

2017-12-20T02:59:30.2433610Z ##[error]Process completed with exit code 0 and had 1 error(s) written to the error stream.

2017-12-20T02:59:30.2745493Z Finishing task: PowerShell

2017-12-20T02:59:30.2745493Z ##[error]Task PowerShell failed. This caused the job to fail. Look at the logs for the task for more details.

Build output image

Below is part of the powershell script where the error is occurring:

[CmdletBinding()]
param()
Push-Location $PSScriptRoot
& git fetch origin
& git checkout master
& git merge origin/master --ff-only
Pop-Location
Write-Host
Write-Host "Success" -ForegroundColor Green

Any idea?

1

1 Answers

1
votes

I found my solution from here

Since git will write to stderr even if successful (e.g. pull when in sync), this handles those cases and writes out first line of output, which is usually what you need to know