Jenkins 错误:WorkflowScript:65:意外标记:} @ 第 65 行,第 1 列。代码行不存在

问题描述 投票:0回答:1

人类鹿大家好

我有一个在 docker 上运行的管道,我想用它构建 2 个镜像。

但是每次我运行它时都会收到此错误:

Started by user Elias Spycher

Checking out git https://github.com/Raisybear/cards_against_humanity into /var/jenkins_home/workspace/cards_against_humanity_pipeline@script/e46138fc9cf8660b857590cb378b6696fff12b52d585f68b61e8f5072062f6a5 to read Jenkinsfile
The recommended git tool is: NONE
No credentials specified
 > git rev-parse --resolve-git-dir /var/jenkins_home/workspace/cards_against_humanity_pipeline@script/e46138fc9cf8660b857590cb378b6696fff12b52d585f68b61e8f5072062f6a5/.git # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/Raisybear/cards_against_humanity # timeout=10
Fetching upstream changes from https://github.com/Raisybear/cards_against_humanity
 > git --version # timeout=10
 > git --version # 'git version 2.39.5'
 > git fetch --tags --force --progress -- https://github.com/Raisybear/cards_against_humanity +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/main^{commit} # timeout=10
Checking out Revision 6dbd5f7a38d90da89675e6bc38f19f33c7f4c92a (refs/remotes/origin/main)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 6dbd5f7a38d90da89675e6bc38f19f33c7f4c92a # timeout=10
Commit message: "Update Jenkinsfile"
 > git rev-list --no-walk 6dbd5f7a38d90da89675e6bc38f19f33c7f4c92a # timeout=10
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 65: unexpected token: } @ line 65, column 1.
   }
   ^

1 error

    at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:309)
    at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:149)
    at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:119)
    at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:131)
    at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:349)
    at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:225)
    at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:191)
    at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:233)
    at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:189)
    at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:966)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:626)
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:602)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:579)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:323)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:293)
    at PluginClassLoader for script-security//org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox$Scope.parse(GroovySandbox.java:163)
    at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:190)
    at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:175)
    at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:652)
    at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:598)
    at PluginClassLoader for workflow-job//org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:335)
    at hudson.model.ResourceController.execute(ResourceController.java:101)
    at hudson.model.Executor.run(Executor.java:446)
Finished: FAILURE

此时我不知道更多了,那么第 65 行在我的 Jenkinsfile 中不存在。最后一行是 63。

pipeline {
    agent any

    environment {
        BACKEND_IMAGE = "backend_image"
        FRONTEND_IMAGE = "frontend_image"
    }

    stages {
        stage('Checkout') {
            steps {
                git branch: 'main', url: 'https://github.com/Raisybear/cards_against_humanity'
            }
        }   
  
        stage('Backend Build') {
            steps {
                dir('Game/cards_against_humanity_backend') {
                    script {
                        sh 'docker build -t ${BACKEND_IMAGE} .'  // Baut das Docker-Image für das Backend.
                    }
                }
            }
        }

        stage('Frontend Build') {
            steps {
                dir('Game/cards_against_humanity_frontend') {
                    script {
                        sh 'docker build -t ${FRONTEND_IMAGE} .'  // Baut das Docker-Image für das Frontend.
                    }
                }
            }
        }

        stage('Run Tests') {
            steps {
                // Tests im Backend-Verzeichnis ausführen
                dir('Game/cards_against_humanity_backend') {
                    sh 'dotnet test'  // Führt die Backend-Tests aus.
                }
                // Tests im Frontend-Verzeichnis ausführen
                dir('Game/cards_against_humanity_frontend') {
                    sh 'npm install && npm test'  // Führt die Frontend-Tests aus.
                }
            }
        }

        stage('Deploy with Docker Compose') {
            steps {
                script {
                    sh 'docker-compose -f docker-compose.yml up -d'  // Startet die Container im Hintergrund.
                }
            }
        }
    }

    post {
        always {
            sh 'docker-compose -f docker-compose.yml down'  // Stoppt und entfernt die Container nach Abschluss der Pipeline.
        }
    }
}

我是德国人,所以忽略评论,存储库链接在错误消息中......

我尝试了许多不同版本的 Jenkinsfile,添加了错误消息、回显、调试步骤,但一切都导致了上面显示的错误。回声也从未被打印过,所以我认为 Jenkinsfile 之外的东西被搞乱了。

如果你能帮助我,我会很高兴。

docker jenkins jenkins-pipeline jenkins-groovy
1个回答
0
投票

您没有执行您发布的 Jenkinsfile。根据您的日志,您的管道来自提交 6dbd5f7a38d90da89675e6bc38f19f33c7f4c92a 并且它有太多右括号here

© www.soinside.com 2019 - 2024. All rights reserved.