Ste*_*ing 4 jenkins jenkins-pipeline
如何使用Groovy代码设置可以在Jenkins主服务器中配置的Jenkins 全局管道库?
Joa*_*oan 10
源自StephenKing的伟大答案,以下是使用以下方法为ModernSCM做的新方法GitSCMSource
:
import org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever;
import org.jenkinsci.plugins.workflow.libs.LibraryConfiguration;
import jenkins.plugins.git.GitSCMSource;
def globalLibsDesc = Jenkins.getInstance()
.getDescriptor("org.jenkinsci.plugins.workflow.libs.GlobalLibraries")
SCMSourceRetriever retriever = new SCMSourceRetriever(new GitSCMSource(
"someId",
"mygitrepo",
"credentialId",
"*",
"",
false))
LibraryConfiguration pipeline = new LibraryConfiguration("pipeline", retriever)
.setDefaultVersion(env.BRANCH_NAME)
.setImplicit(true)
globalLibsDesc.get().setLibraries([pipeline])
Run Code Online (Sandbox Code Playgroud)
配置可以通过org.jenkinsci.plugins.workflow.libs.GlobalLibraries
以下方式访问:
import org.jenkinsci.plugins.workflow.libs.*
import hudson.scm.SCM;
import hudson.plugins.git.*;
def inst = Jenkins.getInstance()
def desc = inst.getDescriptor("org.jenkinsci.plugins.workflow.libs.GlobalLibraries")
Run Code Online (Sandbox Code Playgroud)
假设有一个Git仓库,我们可以按如下方式定义SCM:
SCM scm = new GitSCM("https://git.example.com/foo.git")
SCMRetriever retriever = new SCMRetriever(scm)
Run Code Online (Sandbox Code Playgroud)
每个库都是一个实例,LibaryConfiguration
最后使用setLibraries()
:
def name = "pipeline"
LibraryConfiguration libconfig = new LibraryConfiguration(name, retriever)
desc.get().setLibraries([libconfig])
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2657 次 |
最近记录: |