简体   繁体   中英

Jenkins Pipeline - Git Plugin 3.1.0 - rawRefSpecs not working

I am using Jenkins with the Pipeline Plugin and the Git plugin version 3.1.0. According to this ticket: https://issues.jenkins-ci.org/browse/JENKINS-40908 , this feature is part of the 3.1.0 version.

I am nevertheless unsuccessful with setting the rawRefSpecs variable.

Here is my pipe configuration:

git url: 'ssh://foo/bar.git',
    rawRefSpecs: '+refs/changes/*:refs/changes/*',
    branch: 'bar',
    ...

and here is output when I run the plan:

 > /usr/bin/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > /usr/bin/git config remote.origin.url ssh://foo/bar.git # timeout=10
Fetching upstream changes from ssh://foo/bar.git
 > /usr/bin/git --version # timeout=10
using GIT_SSH to set credentials 
 > /usr/bin/git fetch --tags --progress ssh://foo/bar.git +refs/heads/*:refs/remotes/origin/*
 > /usr/bin/git rev-parse refs/remotes/origin/bar^{commit} # timeout=10
 > /usr/bin/git rev-parse refs/remotes/origin/origin/bar^{commit} # timeout=10
 > /usr/bin/git rev-parse origin/bar^{commit} # timeout=10

We can see that the fetch keeps the default parameter values for the refspecs.

It looks like the GitStep forces the branchspec to be "*/"+branch and ignore any other parameter than branch, credentialsId and url.

https://github.com/jenkinsci/git-plugin/blob/f6ace83fe36740a1ab35612d3b4c5b400647f6ea/src/main/java/jenkins/plugins/git/GitStep.java

How could I pass refspec to the command then?

The Git plugin has supported specifying your own refspec for years. You can find the correct Pipeline syntax via the Snippet Generator , under Checkout: General SCM > Git > Repositories > Advanced > Refspec. This will give you the checkout syntax you need.

The git step itself does not currently support custom refspecs, and the bug you refer to applies to GitSCMSource which, as mentioned in the description, is used for Multibranch Pipelines.

If you're using a Multibranch Pipeline, the new refspec option you're talking about can be found under Branch Sources > Git > Advanced > RefSpecs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM