我们正在迁移到使用管道。我们有几十个构建,所以我试图创建一个单独的管道在构建之间共享。我已阅读博客文章并按照示例进行操作,但我似乎无法在构建服务器上进行此操作。我今天更新了插件,但是我收到了以下错误,这让我觉得我在某处丢失了全局上下文,因为它没有正确地关联any
,即使我复制了{{{ 3}}
[Pipeline] End of Pipeline
groovy.lang.MissingPropertyException: No such property: any for class: myPipeline
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:458)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.getProperty(DefaultInvoker.java:39)
at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
at myPipeline.call(/var/jenkins_home/jobs/SpringBootApps-Git/jobs/abc-multibranch/branches/enable-multibranch/builds/17/libs/my-customer-lib/vars/myPipeline.groovy:56)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.call(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:56)
at myPipeline.call(/var/jenkins_home/jobs/SpringBootApps-Git/jobs/abc-multibranch/branches/enable-multibranch/builds/17/libs/my-customer-lib/vars/myPipeline.groovy:55)
at WorkflowScript.run(WorkflowScript:3)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74)
at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:66)
at sun.reflect.GeneratedMethodAccessor516.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
at com.cloudbees.groovy.cps.Next.step(Next.java:83)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$101(SandboxContinuable.java:34)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE
MY-客户LIB /瓦尔/ myPipeline.groovy
#!groovy
def call(body) {
// evaluate the body block, and collect configuration into the object
def pipelineParams = [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = pipelineParams
body()
def APP_NAME = 'abc'
def WEBAPP_LOCATION
def UI_LOCATION
def VERSION
def NAME
def isMergeRequest = !!env.gitlabMergeRequestLastCommit
def isDeployed = env.gitlabSourceBranch == "develop" || env.BRANCH_NAME == "develop"
def handleCheckout = { ->
if(isMergeRequest) {
sh "echo 'Merge request detected. Merging...'"
checkout changelog: true, poll: true, scm: [
$class: 'GitSCM',
branches: [[name: "origin/${env.gitlabSourceBranch}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [
[$class: 'PreBuildMerge',
options: [
fastForwardMode: 'FF',
mergeRemote: 'origin',
mergeStrategy: 'default',
mergeTarget: env.gitlabTargetBranch
]
],
[$class: 'PruneStaleBranch'],
[$class: 'CleanCheckout']
],
submoduleCfg: [],
userRemoteConfigs: [[name: 'origin', url: 'ssh://git@myserver:20022/app/abc.git']]
]
} else {
sh "echo 'No merge request detected. Checking out current branch'"
checkout ([
$class: 'GitSCM',
branches: scm.branches,
extensions: [
[$class: 'PruneStaleBranch'],
[$class: 'CleanCheckout']
],
userRemoteConfigs: scm.userRemoteConfigs
])
}
}
pipeline {
agent any //ERROR COMES HERE: line 56
environment {
// there is likely a better way to make this happen - but the documentation doesn't seem to reflect reality
// this assumes you have a tool named docker in the jenkins->configureTools->dockerInstalations. make sure you
// have the tool from install latest from Docker.io
PATH = "${tool 'docker'}/bin:$PATH"
}
stage('Checkout') {
steps {
script {
handleCheckout()
}
}
}
stage('Environment') {
steps {
script {
def workspace = pwd()
WEBAPP_LOCATION = "${workspace}/${APP_NAME}-webapp"
UI_LOCATION = "${workspace}/${APP_NAME}-ui"
echo "webapp is at: ${WEBAPP_LOCATION}"
echo "ui is at: ${UI_LOCATION}"
VERSION = 'DEV-SNAPSHOT';
NAME = 'abc';
// print all environment variables
sh 'printenv'
echo "version: ${VERSION}"
echo "name: ${NAME}"
echo "path: ${PATH}"
echo "DOCKER_SERVER: ${DOCKER_SERVER}"
echo "DOCKER_REGISTRY: ${DOCKER_REGISTRY}"
echo "MERGE REQUEST: ${env.gitlabMergeRequestLastCommit}"
}
updateGitlabCommitStatus name: 'build', state: 'running'
}
}
}
}
Jenkinsfile
@Library('my-customer-lib') _
myPipeline {
projectId = 'abc'
}