【发布时间】:2021-06-25 19:05:00
【问题描述】:
我有 Jenkinsfile(脚本流水线)
def template1 = "spread_sshkeys"
node {
// Clean before build
stage('Checkout') {
deleteDir()
checkout scm
sh "git submodule foreach --recursive git pull origin master";
}
stage("import template ${template1}") {
script{
sh "ls -las; cd jenkins-ci-examples; ls -las";
jenkins_ci_examples.sub_module = load "jenkins-ci-examples/${template1}"
}
}
stage("run template ${template1}") {
sh "echo ${jenkins_ci_examples.sub_module}";
}
}
想要转换为声明式
def template1 = "spread_sshkeys"
pipeline {
agent any
stages {
stage ("Checkout") {
steps {
deleteDir()
checkout scm
sh "git submodule foreach --recursive git pull origin master"
}
}
stage("import template ${template1}") {
steps {
script {
sh "ls -las; cd jenkins-ci-examples; ls -las";
jenkins_ci_examples.sub_module = load "jenkins-ci-examples/${template1}"
}
}
}
stage("run template ${template1}") {
steps {
sh "echo ${jenkins_ci_examples.sub_module}";
}
}
}
}
启动 Jenkins Job 后停止并返回错误
WorkflowScript: 22: Expected string literal @ line 22, column 19.
stage("import template ${template1}") {
^
WorkflowScript: 30: Expected string literal @ line 30, column 19.
stage("run template ${template1}") {
^
尝试使用
stage('run template ${template1}')
还有
stage('run template '+template1)
也返回错误。
如何解决这个问题?
【问题讨论】:
-
错误信息暗示你不能这样做。
标签: jenkins jenkins-pipeline jenkins-groovy jenkins-job-dsl jenkins-declarative-pipeline