8

Within my Jenkins pipeline script, I would like to do something like this:

sh("git tag ${BUILD_NUMBER}")

However, this wouldn't work if git isn't found on the shell.

Is there any Jenkins plugin that can do this from a Jenkins pipeline script?

4
  • what about this Commented Mar 2, 2017 at 9:08
  • In my "Jenkins pipeline script" ... Commented Mar 2, 2017 at 9:09
  • to use the git command in a shell you need to have GIT on the path. Commented Mar 2, 2017 at 10:05
  • I don't need it on the path if I'm installing it automatically from Jenkins, which I am. Commented Mar 2, 2017 at 10:15

3 Answers 3

6

There is no plugin support for this currently but might be in the future:
https://issues.jenkins-ci.org/browse/JENKINS-28335

While you go over this Jira issue take a look at Andrey Makeev's temporary solution. also documented here.

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

3 Comments

Rather than linking, you should go ahead and outline the solution here - this prevents link rot from making your otherwise "correct" answer unusable.
Thanks @rbellamy well noted. Since this is not my solution I didn't want to take credit for it.
that's attribution, which you can still do by including the link. Take a look at my answer and you'll see the format that's pretty much the accepted method for ensuring attribution AND preventing link rot.
4

Here's how I do it, where shell and Version are custom functions and class, respectively, and shell is a drop-in replacement for the sh function:

    void gitTag(Version releaseVersion) {
      sshagent(['devops_deploy_DEV']) {
        shell 'git tag -d \$(git tag)'
        shell 'git fetch --tags'
        echo "New release version ${releaseVersion.normalVersion}"
        shell "git tag -fa ${releaseVersion.normalVersion} -m 'Release version ${releaseVersion.normalVersion}'"
      }
    }

You can find the source for this here.

1 Comment

This creates the git tag, but doesn't push it back to git server?
0

You can use the Git-Client plugin to make things like this: sh "git tag build_${gitCommit}"

2 Comments

I have the plugin installed and I already tried this, but I'm getting git: command not found
This is not using the Git-Client plugin, just basic Git comand from your master/slave node.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.