Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipeline get tag list

I am trying to get the latest tag from a repo Jenkinsfile (using Blue Ocean Declarative Pipelines) but it throws an error.

Command:

def tag = sh(script: 'git describe --tags $(git rev-list --tags --max-count=1)', returnStdout: true).trim()

Expected output:

v2.4.1

But I get:

fatal: No names found, cannot describe anything.

I went into the workspace and executed the command manually and received the same fatal error but when I clone manually I am able to get the version. Am I missing something with Jenkins Pipelines?

Note: I am able to get the commit id and branch name. Not the tags.

like image 298
Squirrel Avatar asked Oct 27 '25 09:10

Squirrel


2 Answers

The problem was that pipelines do not fetch tags. You have to go into the advanced clone settings and enable fetch tags.

like image 175
Squirrel Avatar answered Oct 30 '25 15:10

Squirrel


The solution is described here: https://issues.jenkins-ci.org/browse/JENKINS-45164

Instead of using checkout scm use:

checkout([
    $class: 'GitSCM',
    branches: scm.branches,
    doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
    extensions: [[$class: 'CloneOption', noTags: false, shallow: false, depth: 0, reference: '']],
    userRemoteConfigs: scm.userRemoteConfigs,
])

Note, it will require by approving script access to methods scm.branches, scm.userRemoteConfigs etc

like image 24
Alexander Matyushentsev Avatar answered Oct 30 '25 13:10

Alexander Matyushentsev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!