I'm trying to handle a git script in VSTS tasks with Powershell, but it's not working as expected.
What I'm doing is fetching latest commits messages after the latest tag to put inside a Release Notes, this is the base git command:
git log `git describe --tags --abbrev=0`..HEAD --no-decorate --no-merges --abbrev=0 --pretty=format:"%s"
But Powershell doesn't accept this format, so I do the following:
$latestTag = git describe --tags --abbrev=0
$releaseNotes = git log $latestTag..HEAD --no-decorate --no-merges --abbrev=0 --pretty=format:"%s"
It seems that when I put the variable $latestTag next to ..HEAD it breaks line, if I specify the tag eg. v1.2.9 instead of the variable it works well.
What can I do to make it run properly ? Thanks.
You can enclose the expression $latestTag..HEAD in " marks, as
$latestTag = git describe --tags --abbrev=0
$releaseNotes = git log "$latestTag..HEAD" --no-decorate --no-merges --abbrev=0 --pretty=format:"%s"
This has something to do with how PowerShell expands variables, but I don't use PS enough to really understand it.
If you want to keep it on a single line you might be able to try the powershell syntax for embedding a comment with something like your original. Translating to powershell-friendly statements I think it would be something like
git log $(git describe --tags --abbrev=0)..HEAD --no-decorate --no-merges --abbrev=0 --pretty=format:"%s"
This should resolve the expression inside $() and then insert that result as text to the git log command much like your original.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With