我需要在Jenkins的“环境”变量之一中进行三元运算。可能吗?例如。 Sample_Variable
pipeline {
parameters {
booleanParam (defaultValue: false,
description: 'Check this if you want to do allow comments?',
name: 'ALLOW_COMMENTS')
string(name: 'ENTER_COMMENTS', defaultValue: '', description: 'Allow comments for this example..')
}
environment {
Sample_Variable: "${params.ALLOW_COMMENTS == true ? params.ENTER_COMMENTS:env.SOME_OTHER_ENV_VARIABLE}"
}
}
我搜索了互联网,但一无所获。我尝试了类似上面的操作,但是会引发错误:
Obtained Jenkinsfile from d1b56c1a276aa09424c88f25e052359f35f1a64c
Running in Durability level: MAX_SURVIVABILITY
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during class generation: Method code too large!
java.lang.RuntimeException: Method code too large!
at groovyjarjarasm.asm.MethodWriter.a(Unknown Source)
at groovyjarjarasm.asm.ClassWriter.toByteArray(Unknown Source)
at org.codehaus.groovy.control.CompilationUnit$17.call(CompilationUnit.java:827)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1065)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:131)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:125)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:560)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:521)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:325)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
答案 0 :(得分:0)
您应该尝试:
environment {
Sample_Variable: (params.ALLOW_COMMENTS) ? "${params.ENTER_COMMENTS}" : "${env.SOME_OTHER_ENV_VARIABLE}"
}