【发布时间】:2020-01-29 07:58:27
【问题描述】:
我正在尝试拥有一个具有实际管道即代码的公共共享库,类似于 vars/demo.groovy
下的内容def call(Map pipelineParams) {
pipeline {
agent {
docker { image 'centos:latest' }
}
stages {
stage("Env Variables") {
steps {
sh "printenv"
//echo ${SERVICE_NAME}
}
}
stage("test") {
steps {
sh "printenv"
}
}
}
}
}
我将像这样从我的 Jenkinsfile 访问共享库。
library identifier: 'mylibraryname@master',
//'master' refers to a valid git-ref
//'mylibraryname' can be any name
retriever: modernSCM([
$class: 'GitSCMSource',
//credentialsId: 'your-credentials-id',
remote: 'GIT URL'
])
demo()
它按预期工作,但我想发送一个额外的环境变量或覆盖我的 Jenkinsfile 中的现有变量,而不更改将我的管道作为代码的共享库。你能帮我解决这个问题吗?
我尝试给出如下变量:
demo {
service = 'test'
var1 = 'value'
}
并尝试他们以这种方式访问:
def call(Map pipelineParams) {
pipeline {
agent {
docker { image 'centos:latest' }
}
stages {
stage("Env Variables") {
steps {
sh "printenv"
echo "pipelineParams.service"
}
}
stage("test") {
steps {
sh ' echo "hello pipelineParams.service '
}
}
}
}
}
但出现以下错误:
[Pipeline] End of Pipeline
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: demo.call() is applicable for argument types: (org.jenkinsci.plugins.workflow.cps.CpsClosure2) values: [org.jenkinsci.plugins.workflow.cps.CpsClosure2@cad5c94]
Possible solutions: call(java.util.Map), wait(), any(), wait(long), main([Ljava.lang.String;), each(groovy.lang.Closure)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:64)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:160)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:157)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:142)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:158)
【问题讨论】:
-
我做了一个库来满足这个特定的需求,它还自动处理创建作业新作业,并且不需要执行管道来获取它的参数github.com/SAP/jenkins-pipelayer
标签: jenkins jenkins-pipeline shared-libraries