我開始學習使用 Jenkins 并想讓它自動運行我的 Python 腳本。我按照他們的教程創建了一個名為Pipeline Test.
我還添加了我想測驗的 Python 腳本的 GitHub 存盤庫 ( https://github.com/mateasmario/spam-bot )。
如您所見,我Jenkinsfile在該存盤庫中創建了一個。因為我的腳本名為spam-bot.py,所以我希望每次在 Jenkins 中單擊“立即構建”時我的 Jenkinsfile 都運行該腳本。這是我的 Jenkinsfile 的內容:
Jenkinsfile (Declarative Pipeline)
pipeline {
agent { docker { image 'python:3.10.1-alpine' } }
stages {
stage('build') {
steps {
sh 'python spam-bot.py'
}
}
}
}
問題是,每當我單擊“立即構建”時,我的構建都會失敗并且控制臺會輸出以下錯誤:
Started by user Mario Mateas
Obtained Jenkinsfile from git https://github.com/mateasmario/spam-bot.git
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 1: unable to resolve class Declarative
@ line 1, column 26.
Jenkinsfile (Declarative Pipeline)
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:958)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:605)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:554)
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:142)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:571)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:523)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:334)
at hudson.model.ResourceController.execute(ResourceController.java:99)
at hudson.model.Executor.run(Executor.java:432)
Finished: FAILURE
我在互聯網上查找了這個錯誤,但沒有找到任何有用的資訊,這就是我決定在這里提問的原因。我也沒有配置任何 Docker 容器。我需要配置一個嗎?我查看了 Jenkins 的 Docker 檔案,但沒有看到任何將 Python 映像(如 開頭提到的Jenkinsfile)添加到容器的有用資訊。
uj5u.com熱心網友回復:
您Jenkinsfile的第一行包含無效語法,這就是拋出錯誤的原因。假設您打算將第一行作為注釋,您可以將管道代碼修改為:
// Jenkinsfile (Declarative Pipeline)
pipeline {
...
}
并且您的管道代碼將具有有效的語法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/392479.html
上一篇:Dockercompose不會從compose檔案中提取所有影像
下一篇:CMD錯誤["supervisord","-c","/etc/supervisor.conf"]和USERnon-root
