简体   繁体   中英

Jenkins multibranch pipeline use Variable in Project Repository

Our Jenkins instance holds a lot of pipelines that their source is in a private git server, so all the paths are ${SERVER_URL}/group/repo.git .

Today, we are using a hard-coded path all over the Jenkins Pipeline Configurations and Jenkinsfile , but in order to replace the server, we want to generalize this URL, to be able to replace it in one place.

We defined it as a Global Variable in Jenkins Configuration , and now we can use it in Jenkinsfiles by ${env.SERVER_URL} , and in Pipeline Configuration by ${SERVER_URL} :

在此处输入图像描述


The Question

Now, I can't do that in the Multibranch Pipeline . Using similar configuration:

在此处输入图像描述

I'm getting the next error from the Scan Multibranch Pipeline Log :

Started
[Wed Feb 24 16:54:59 IST 2021] Starting branch indexing...
 > git --version # timeout=10
 > git --version # 'git version 1.8.3.1'
using GIT_ASKPASS to set credentials tfsservices
 > git ls-remote ${SERVER_URL}/MyGroup/MyProject # timeout=10
ERROR: [Wed Feb 24 16:54:59 IST 2021] Could not update folder level actions from source f3de808c-bb6b-49f3-b4f3-08a1b4e749f5
hudson.plugins.git.GitException: Command "git ls-remote ${SERVER_URL}/MyGroup/MyProject" returned status code 128:
stdout: 
stderr: fatal: '${SERVER_URL}/MyGroup/MyProject' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2450)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2051)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1951)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1942)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getRemoteReferences(CliGitAPIImpl.java:3381)
    at jenkins.plugins.git.AbstractGitSCMSource.retrieveActions(AbstractGitSCMSource.java:1148)
    at jenkins.scm.api.SCMSource.fetchActions(SCMSource.java:848)
    at jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:598)
    at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:278)
    at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:165)
    at jenkins.branch.MultiBranchProject$BranchIndexing.run(MultiBranchProject.java:1032)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:427)
[Wed Feb 24 16:54:59 IST 2021] Finished branch indexing. Indexing took 22 ms
FATAL: Failed to recompute children of build-name
hudson.plugins.git.GitException: Command "git ls-remote ${SERVER_URL}/MyGroup/MyProject" returned status code 128:
stdout: 
stderr: fatal: '${SERVER_URL}/MyGroup/MyProject' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2450)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2051)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1951)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1942)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getRemoteReferences(CliGitAPIImpl.java:3381)
    at jenkins.plugins.git.AbstractGitSCMSource.retrieveActions(AbstractGitSCMSource.java:1148)
    at jenkins.scm.api.SCMSource.fetchActions(SCMSource.java:848)
    at jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:598)
    at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:278)
    at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:165)
    at jenkins.branch.MultiBranchProject$BranchIndexing.run(MultiBranchProject.java:1032)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:427)
Finished: FAILURE

Yes it does not support. You can use Single repository & branch .

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