1

I want to take this buildVariable

Build.SourceVersion

which will equal for example:

0gc58d92d905d62415b8866g3f48f17416da426s

And replace from digit [7] till line end with empty string

0gc58d92

I tried

- ShortCommitId: ${{ replace(variables['Build.SourceVersion'], '[[8]-$]','') }}

but it didn't work

Shnbook
  • 11
  • 2

1 Answers1

1

The substring() method will take the string value from Build.SourceVersion and can be passed two int parameters. One will output the string value starting at a specific character position, and the other tell it what subsequent character positions characters to output.

$a = "0gc58d92d905d62415b8866g3f48f17416da426s"
$a.substring(0,7)

Output

0gc58d9

Pass the substring() method just one int parameter telling it the starting character position to just output all subsequent character position characters until the end of the string.

$a = "0gc58d92d905d62415b8866g3f48f17416da426s"
$a.substring(8)

Output

d905d62415b8866g3f48f17416da426s

Supporting Resource

  • Substring()

  • String.Substring Method

    Substring(Int32)

    • Retrieves a substring from this instance. The substring starts at a specified character position and continues to the end of the string.

    Substring(Int32, Int32)

    • Retrieves a substring from this instance. The substring starts at a specified character position and has a specified length.
Pimp Juice IT
  • 1,077
  • 1
  • 9
  • 16
  • This solution should help you get what you need, but let me know if you run into any snag, I'm happy to adjust to accommodate further if needed. – Pimp Juice IT Dec 30 '22 at 04:09
  • I'm sorry but it didn't – Shnbook Jan 02 '23 at 06:12
  • @Shnbook If you have this value to start with `0gc58d92d905d62415b8866g3f48f17416da426s` what is the desired (or an example) final result you want that to be. I probably just need to understand better but if you can help clarify a little further to help me better understand, I should be able to help you figure out what you need. Let me know. – Pimp Juice IT Jan 02 '23 at 09:14
  • @Shnbook See above comment but if you can share more of the fully logic in a script, etc. you are using, that may help me fine tune this method better for your use case. Otherwise, I'm left to play with a string basically but if that's not working for your command when you integrate it, I just need to see more logic to see what trivial adjustments are needed to make it work properly. – Pimp Juice IT Jan 13 '23 at 14:07