Jenkins: groovy.lang.MissingPropertyException: No such prope



我有一个奇怪的问题。我正在詹金斯CasC管道上工作,以在启动时自动填充工作。一切都很好,直到我开始添加参数。从作业中运行添加的以下代码第一次失败,然后当我随后重新运行时,它可以工作。我在一个论坛上发现,运行Groovy代码需要注册参数,这就是为什么从第二次构建开始工作的原因。它还指出,通过CasC加载这个第一次错误不是问题。然而,通过CasC加载会产生以下错误。请注意,当从代码中保存并出现第一次错误时,确切的代码可以正常工作。

错误:

hudson.remoting.ProxyException: groovy.lang.MissingPropertyException: No such property: app for class: WorkflowScript
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:66)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:471)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.getProperty(DefaultInvoker.java:39)
at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
at WorkflowScript.run(WorkflowScript:19)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.delegateAndExecute(ModelInterpreter.groovy:137)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.executeSingleStage(ModelInterpreter.groovy:666)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.catchRequiredContextForNode(ModelInterpreter.groovy:395)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.catchRequiredContextForNode(ModelInterpreter.groovy:393)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.executeSingleStage(ModelInterpreter.groovy:665)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.evaluateStage(ModelInterpreter.groovy:288)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.toolsBlock(ModelInterpreter.groovy:544)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.toolsBlock(ModelInterpreter.groovy:543)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.evaluateStage(ModelInterpreter.groovy:276)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withEnvBlock(ModelInterpreter.groovy:443)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withEnvBlock(ModelInterpreter.groovy:442)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.evaluateStage(ModelInterpreter.groovy:275)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withCredentialsBlock(ModelInterpreter.groovy:481)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withCredentialsBlock(ModelInterpreter.groovy:480)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.evaluateStage(ModelInterpreter.groovy:274)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.inDeclarativeAgent(ModelInterpreter.groovy:595)
at org.jenkinsci.plugins.pipeline.modeldefinition.agent.CheckoutScript.checkoutAndRun(CheckoutScript.groovy:64)
at org.jenkinsci.plugins.pipeline.modeldefinition.agent.CheckoutScript.doCheckout(CheckoutScript.groovy:40)
at org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.LabelScript.run(LabelScript.groovy:43)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:73)
at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:65)
at jdk.internal.reflect.GeneratedMethodAccessor288.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
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:152)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:146)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:136)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:275)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:146)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:187)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:420)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:330)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:294)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
at jenkins.util.ErrorLoggingExecutorService.lambda$wrap$0(ErrorLoggingExecutorService.java:51)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Finished: FAILURE

Jenkins版本:2.387.1
插件:
Config as Code: 1569.vb_72405b_80249
Config as Code
groovy扩展:1.1
管道:596。V8c21c963d92d
管道groovy: 3653V07ea_433c90b_4
管道groovy库:629.vb_5627b_ee2104

下面是我的脚本:

pipeline {
agent none
parameters {
choice(name: 'app', choices: ['app1', 'app2'], description: 'Select the app.')
choice(name: 'app_year', choices: ['', '2023', '2022', '2021'], description: 'Select the app year.')
choice(name: 'deploy_env', choices: ['builds'], description: 'Default is builds.')
choice(name: 'feature', choices: ['', 'feat1', 'feat2', 'feat3'], description: 'Select the feature, leave blank for all.')
}
triggers {
cron('H/15 * * * *')
}
stages {
stage ('App Healthcheck') {
agent { label 'test-deploy01' }
options {
timeout(time: 3600, unit: 'SECONDS')
}
steps {
sh "cd /opt/tools/ansible/${app}/scripts/; 
PYTHONPATH=shared python app_service_check.py -y $app_year -e $deploy_env -p $feature"
}
}
}
}

我通过GUI粘贴了上面的内容。点击新建项目——>管道——比;将groovy脚本粘贴到页面并保存。

第一次运行,得到上面的错误。然而,这确实在作业中注册了参数选项,现在我可以毫无问题地运行作业,并得到每个参数的提示,脚本工作没有问题。

我需要通过CasC加载许多作业,但是由于上述错误,Jenkins无法启动,因此我无法在GUI中重新运行作业以解决此问题。

我该如何解决这个问题?

是的@grzegorzgrzegorz这就是Jenkins的工作方式,这对我来说很奇怪。我通过设置一个pull pipeline作业来解决这个问题。

例如:

在我的詹金斯。我有:

jobs:
- script: >
folder('App')
- file: /var/jenkins_home/pipelines/pull_stop_job

在我的pull_job脚本中,我有这个:

pipelineJob("App/Server Stop") {
definition {
cpsScm {
scm {
git {
remote {
url("https://gitlab.domian.com/Repo/Common/tools/jenkins.git")
credentials("<gitlab_token>")
}
branch('develop')
}
}
scriptPath("jobs/*")
}
}
triggers {
scm('H/15 * * * *')
}
}

然后我可以使用我最初发布的脚本:

pipeline {
agent none
parameters {
choice(name: 'app', choices: ['app1', 'app2'], description: 'Select the app.')
choice(name: 'app_year', choices: ['', '2023', '2022', '2021'], description: 'Select the app year.')
choice(name: 'deploy_env', choices: ['builds'], description: 'Default is builds.')
choice(name: 'feature', choices: ['', 'feat1', 'feat2', 'feat3'], description: 'Select the feature, leave blank for all.')
}
triggers {
cron('H/15 * * * *')
}
stages {
stage ('App Healthcheck') {
agent { label 'test-deploy01' }
options {
timeout(time: 3600, unit: 'SECONDS')
}
steps {
sh "cd /opt/tools/ansible/${app}/scripts/; 
PYTHONPATH=shared python app_service_check.py -y $app_year -e $deploy_env -p $feature"
}
}
}
}

如前所述,作业第一次将失败,但之后作业提示正确输入参数并可以使用。虽然不完美,但很有效。

相关内容

  • 没有找到相关文章

最新更新