Jenkins流水线脚本错误,意外的标记: }

huangapple go评论64阅读模式
英文:

Jenkins pipeline script error unexpected token: }

问题

我有一个简单的流水线作业,遵循 Jenkins 文档示例 https://www.jenkins.io/doc/book/pipeline/syntax/ 中的 "示例 2. 阶段级代理部分" 部分。但我无法理解为什么会出现以下错误:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 7: unexpected token: } @ line 7, column 13.
               }
               ^
1 error

我已重新输入,逐行检查字符并粘贴到编辑器中,以查看问题出在哪里。以下是我的片段:

pipeline {
    agent { label 'test-deploy01' }
    stages {
        stage ('Change Directory') {
            steps {
                cd /var/jenkins_home/p4/tools/ansible/DL/app/scripts/
            }
        }
        stage ('Blaze Healthcheck') {
            steps {
                PYTHONPATH=shared python app_service_check.py -y 2023 -e test -p pc
            }
        }
    }
}
英文:

I have a simple pipeline job, following Jenkins documentation example https://www.jenkins.io/doc/book/pipeline/syntax/, in the section 'Example 2. Stage-level Agent Section'. For the life of me I cannot figure out why I am getting this error:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 7: unexpected token: } @ line 7, column 13.
               }
               ^
1 error

I have retyped, went through line by line to check for characters and pasted into editor to see if I could see what the issue is. Here is my snippet:

pipeline {
    agent { label 'test-deploy01' }
    stages {
        stage ('Change Directory') {
            steps {
                cd /var/jenkins_home/p4/tools/ansible/DL/app/scripts/
            }
        }
        stage ('Blaze Healthcheck') {
            steps {
                PYTHONPATH=shared python app_service_check.py -y 2023 -e test -p pc
            }
        }
    }
}

答案1

得分: 0

或许你错过了在阶段和步骤之间指定代理的部分。Pipeline 的完整安装位置在代理部分中指定。不需要在阶段级别使用,但必须在 pipeline 块的顶级定义该部分。

stage('Example Build') {
    agent { docker 'maven:3.9.0-eclipse-temurin-11' }
    steps {
        echo 'Hello, Maven'
        sh 'mvn --version'
    }
}

如果这无法解决你的问题,请参考这个YAML Pipeline 教程

英文:

Perhaps you're missing the section between stage and steps that specifies the agent. Where the complete Pipeline is installed is specified in the agent section. Stage-level usage is not required, but the section must be defined at the pipeline block's top level.

  `stage('Example Build') {
        agent { docker 'maven:3.9.0-eclipse-temurin-11' } 
        steps {
            echo 'Hello, Maven'
            sh 'mvn --version'
        }
    }`

If that does not resolve your problem, please refer to this YAML Pipeline Tutorial.

huangapple
  • 本文由 发表于 2023年2月24日 10:59:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75552250.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定