In my Visual Studio Team Services build I am pulling from a bitbucket repo. I am trying to get the commit message and use it in a powershell script.
In my powershell script I have the following code.
param (
##Expect to be passed parameter $(Build.SOURCEVERSIONMESSAGE)
[string]$commitMessage = ""
)
Write-Warning "Source Message: $commitMessage"
Write-Warning "SOURCEVERSIONMESSAGE: $env:Build_SOURCEVERSIONMESSAGE"
Get-ChildItem Env:
Which gives me the following error:
2017-08-24T02:18:27.0938681Z ##[command]. 'd:\a\1\s\Pcmtec.Azure\DeploymentScripts\SetBuildTagTest.ps1' -commitMessage $(Build.SOURCEVERSIONMESSAGE)
2017-08-24T02:18:30.3970727Z ##[error]Build.SOURCEVERSIONMESSAGE : The term 'Build.SOURCEVERSIONMESSAGE' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
At line:1 char:82
+ ... pts\SetBuildTagTest.ps1' -commitMessage $(Build.SOURCEVERSIONMESSAGE)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Build.SOURCEVERSIONMESSAGE:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
2017-08-24T02:18:30.4020718Z WARNING: Source Message:
2017-08-24T02:18:30.4020718Z WARNING: SOURCEVERSIONMESSAGE:
It then prints out all the env variables. The only ones I get are:
BUILD_ARTIFACTSTAGINGDIRECTORY
BUILD_BINARIESDIRECTORY
BUILD_BUILDID
BUILD_BUILDNUMBER
BUILD_BUILDURI
BUILD_CONTAINERID
BUILD_DEFINITIONNAME
BUILD_DEFINITIONVERSION
BUILD_QUEUEDBY
BUILD_QUEUEDBYID
BUILD_REASON
BUILD_REPOSITORY_CLEAN
BUILD_REPOSITORY_GIT_SUBMOD...
BUILD_REPOSITORY_ID
BUILD_REPOSITORY_LOCALPATH
BUILD_REPOSITORY_NAME
BUILD_REPOSITORY_PROVIDER
BUILD_REPOSITORY_URI
BUILD_REQUESTEDFOR
BUILD_REQUESTEDFOREMAIL
BUILD_REQUESTEDFORID
BUILD_SOURCEBRANCH
BUILD_SOURCEBRANCHNAME
BUILD_SOURCESDIRECTORY
BUILD_SOURCEVERSION
BUILD_STAGINGDIRECTORY
BUILDCONFIGURATION
Why is BUILD_SOURCEVERSIONMESSAGE missing?
I don't know, but it was reported missing before, as you noted (and in mentioned here as well).
I would still use the Git command alternative
git log --format='%s' -1
: if there is no value here either, that would at least give a clue.