gpt4 book ai didi

Jenkinsfile 管道错误 : "expected a symbol" and "undefined section"

转载 作者:行者123 更新时间:2023-12-04 23:39:20 25 4
gpt4 key购买 nike

谁能解释为什么我会收到以下错误,以及可能的解决方案是什么?

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 20: Expected a symbol @ line 20, column 4. environment {

WorkflowScript: 17: Undefined section "error" @ line 17, column 1.
pipeline {



Jenkinsfile 中的代码如下:
#!groovy

def application, manifest, git, environment, artifactory, sonar

fileLoader.withGit('git@<reducted>', 'v1', 'ssh-key-credential-id-number') {
application = fileLoader.load('<reducted>');
manifest = fileLoader.load('<reducted>');
git = fileLoader.load('<reducted>');
environment = fileLoader.load('<reducted>');
}

pipeline {
agent { label 'cf_slave' }

environment {
def projectName = null
def githubOrg = null
def gitCommit = null
}

options {
skipDefaultCheckout()
}

stages {
stage ("Checkout SCM") {
steps {
checkout scm

script {
projectName = git.getGitRepositoryName()
githubOrg = git.getGitOrgName()
gitCommit = manifest.getGitCommit()
}
}
}

stage ("Unit tests") {
steps {
sh "./node_modules/.bin/mocha --reporter mocha-junit-reporter --reporter-options mochaFile=./testResults/results.xml"
junit allowEmptyResults: true, testResults: 'testResults/results.xml'
}
}

//stage ("SonarQube analysis") {
//...
//}

// stage("Simple deploy") {
// steps {
// // Login
// sh "cf api <reducted>"
// sh "cf login -u <reducted> -p <....>"
//
// // Deploy
// sh "cf push"
// }
// }
}

post {
// always {

// }
success {
sh "echo 'Pipeline reached the finish line!'"

// Notify in Slack
slackSend color: 'yellow', message: "Pipeline operation completed successfully. Check <reducted>"
}
failure {
sh "echo 'Pipeline failed'"
// Notify in Slack
slackSend color: 'red', message: "Pipeline operation failed!"

//Clean the execution workspace
//deleteDir()
}
unstable {
sh "echo 'Pipeline unstable :-('"
}
// changed {
// sh "echo 'Pipeline was previously failing but is now successful.'"
// }
}
}

最佳答案

你的流水线基本没问题——在声明性 pipeline 之前添加脚本化流水线元素块一般没有问题。

然而,一开始,您定义了一个名为 environment 的变量。 (和 git ),它们基本上覆盖了各种管道插件声明的元素。

即当你尝试做 pipeline { environment { … } } , environment指的是您的变量声明,这会导致出现问题。

重命名这两个变量,您将修复第一条错误消息。

要修复第二条错误消息,请删除 environment 中声明变量的尝试。块 — 此块仅适用于 exporting environment variables在构建步骤中使用,例如:

environment {
FOO = 'bar'
BAR = 'baz'
}
script没有这些声明,您拥有的块将正常工作。或者,您可以将这些变量声明移动到脚本的顶层。

关于Jenkinsfile 管道错误 : "expected a symbol" and "undefined section",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42655474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com