0
votes

I have a Jenkins job called Git_Tag_Test with following job configuration: 1)build with parameters: SHA and tag name are string parameters 2)git scm
3)batch command to tag the branch.

This Git_Tag_Test job is called from a jenkins pipeline after the prod deployment steps. Git_Tag_Test job runs successfully when I enter the SHA and tag name parameters manually without passing it as variables. Problem is when I call the job from pipeline with SHA name and tag name as variables, the SHA is not recognized.

Here is what the batch command looks like:

echo %Tag_Name%
echo %SHA%
git tag -f -a %Tag_Name% %SHA% -m "Test tag"
git push --tags origin

Here's the output from git tag.

C:\Program Files (x86)\Jenkins\workspace\Git_Tag_Test>echo 2.10.6928.18660 
2.10.6928.18660

C:\Program Files (x86)\Jenkins\workspace\Git_Tag_Test>echo 9e47b72e6   
9e47b72e6

C:\Program Files (x86)\Jenkins\workspace\Git_Tag_Test>git tag -f -a 
2.10.6928.18660

Vim: Warning: Output is not to a terminal  
Vim: Warning: Input is not from a terminal  
7[?47h[27m[24m[0m[H[J[24;1H<ogram Files 
(x86)/Jenkins/workspace/Git_Tag_Test/.git/TAG_EDITMSG"
<86)/Jenkins/workspace/Git_Tag_Test/.git/TAG_EDITMSG" [unix] 5L, 
93C[2;1H[1m[36m#
# [0m[1m[34mWrite a message for tag:[0m
[1m[36m#   2.10.6928.18660
# Lines starting with '#' will be ignored.[0m
[1m[34m~                                                                               
[7;1H~                                                                               
[8;1H~                                                                               
[9;1H~                                                                               
[10;1H~                                                                               
[11;1H~                                                                               

Echo shows the tag name and SHA is recognized by passing variables but when running the git tag command the SHA variable is not outputting.

Note: "Trim the string" is checked on for the string parameters configuration.

What exactly is the problem? I've searched everywhere on this issue and have been trying to debug this for months.

1
Also wanted to note this is the same issue when I duplicate the job configuration of git_tag_test job to the pipeline step block (instead of called another build job).jpatel

1 Answers

0
votes

From your console log it really looks like Vim is being opened during the script execution.

Now according to the git tag man page (emphasis added) https://linux.die.net/man/1/git-tag:

If one of -a, -s, or -u is passed, the command creates a tag object, and requires a tag message. Unless -m or -F is given, an editor is started for the user to type in the tag message.

So somehow, it seems like your command is being mangled before it reaches the -m flag.

  • Maybe your parameters have a newline character hidden in them? Try doing some manual cleaning in the script (for this it might be easier to use Powershell).
  • Try moving the -m flag earlier in the command and leave the problem parameter until the very end? git tag -f -m "Test tag" -a %Tag_Name% %SHA%

By the way, I have to admit I am guessing here. Sorry if you have already tried this.