我正在编写我的第一个Jenkins管道。它现在的基本目标是在管道中顺序运行一堆作业,稍后我将添加不同的功能。我正在尝试使用propagate: false
,因此我可以自己处理特定的故障,而不是在作业失败后立即退出并出现错误。请注意,在代码片段中,我展示了我尝试的两种不同方法(作业a和作业b。实际上有大约十几个作业)基本上返回相同的堆栈跟踪。我很难过。如果我在管道的脚本框中尝试它,它可以工作。但如果我在jenkinsfile
中这样做,我会收到错误。
#!groovy
def SUCCESS_LIST = ["SUCCESS", "UNSTABLE"]
stage "Unit Tests"
node ('k8s'){
echo 'Running unit tests..'
currentBuild.result = "SUCCESS"
a = build job 'Some Unit Tests', propagate: false
b = build("Other System Unit Tests"), propagate: false
jobsList<Object> = [a, b]
// check if there was a failure. if so - mark job as 'failed'.
for (job in jobsList){
if (!SUCCESS_LIST.contains(job.result)) {
//currentBuild.result = "FAILURE"
mail to: amos@company_mail.com, subject: 'The Pipeline failed at unit-tests'
}
}
}
Started by user Amos B
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://github.com/my-company/companyone.git # timeout=10
Fetching upstream changes from https://github.com/my-company/companyone.git
> git --version # timeout=10
using .gitcredentials to set credentials
> git config --local credential.username automation@my-company.com # timeout=10
> git config --local credential.helper store --file=/tmp/git6347898027159980380.credentials # timeout=10
> git -c core.askpass=true fetch --tags --progress https://github.com/my-company/companyone.git +refs/heads/*:refs/remotes/origin/*
> git config --local --remove-section credential # timeout=10
> git rev-parse refs/remotes/origin/develop^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/develop^{commit} # timeout=10
Checking out Revision 5d349a17a9ee89d340b63db92a71e159780ea7ad (refs/remotes/origin/develop)
> git config core.sparsecheckout # timeout=10
> git checkout -f 5d349a17a9ee89d340b63db92a71e159780ea7ad
> git rev-list 65a8a33381ae18a1aefdd57a7d64fd3a475407fb # timeout=10
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 8: expecting '}', found ',' @ line 8, column 49.
ild job 'Knowledge Unit Tests', propagat
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:150)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:120)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:132)
at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:360)
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:145)
at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:111)
at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:237)
at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:167)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:931)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:593)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
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.reparse(CpsGroovyShell.java:67)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:410)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:373)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:213)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410)
Finished: FAILURE
无论使用哪种语法(a或b),它都是完全相同的错误。我错过了什么?
答案 0 :(得分:0)
您应该这样做来调用管道中的其他作业。 job
之后缺少冒号会导致错误:
build job: 'job-name'