4

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.

2
  • 1
    Not sure, but try enclosing $latestTag..HEAD in " Commented Dec 29, 2017 at 16:21
  • It worked, latest build was cached, it's now returning the value! Could you please post it so I can accept @MarkAdelsberger Commented Dec 29, 2017 at 16:24

2 Answers 2

9

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.

Sign up to request clarification or add additional context in comments.

1 Comment

A guess I'd say it stops PowerShell from interpreting the .. as a range operator (ie range of 1 to 10 being 1..10) and instead as a string.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.