jenkins:: ERROR: Expected a step @ &将生成的值传递给下游作业 &



我有一个python文件peekaboo.py,它在独立执行时输出如下json。

python文件输出(JSON):
{"fernet_key": "some fernet_key", "db_url": "some_db_url", "pki_password": "some_pki_password"}

然而,当jekins试图运行相同的python文件时,它会失败,如下所示:

顺便说一下,这个python文件应该设置pki_client_cacert_password, db_url, fernet_key的值,这些值将传递给sible playbook
pipeline {
parameters {
string(defaultValue: '', description: '', name: 'pki_client_cacert_password', trim: true)
string(defaultValue: '', description: '', name: 'db_url', trim: true)
}
stages {
stage('DeployToDev') {
steps {
env.artifacts = sh "/var/lib/jenkins/python_jobs/peekaboo_venv/bin/python3 /var/lib/jenkins/python_jobs/peekaboo.py --db_url=${env.db_url} --pki_password=${env.pki_client_cacert_password}"
echo "${env.artifacts}" 
ansiblePlaybook credentialsId: "${env.git_credential_id}", disableHostKeyChecking: true, extras: "-e "pki_client_cacert_password=${env.pki_client_cacert_password} db_url=${env.db_url} fernet_key=${env.fernet_key} use_isrg_freetds=false"",
}
}
}
}

我们得到以下错误

错误:

WorkflowScript: 32: Expected a step @ line 32, column 21.
env.artifacts = sh "/var/lib/jenkins/python_jobs/peekaboo_venv/bin/python3 /var/lib/jenkins/python_jobs/peekaboo.py --db_url=${env.db_url} --pki_password=${env.pki_client_cacert_password}"

我的问题是,

  1. 如何修复此错误
  2. 如何访问生成的值以传递给可见的作业。

您可以尝试使用赋值语句sh:

script{
env.artifacts = sh(
returnStdout: true, 
script: "/var/lib/jenkins/python_jobs/peekaboo_venv/bin/python3 /var/lib/jenkins/python_jobs/peekaboo.py --db_url=${env.db_url} --pki_password=${env.pki_client_cacert_password}"
)
}

这只适用于管道作业,而不是自由式作业。

我必须添加script标签,并且还使用双引号"来括住字符串

script{
env.artifacts = sh(
returnStdout: true, 
script: "/var/lib/jenkins/python_jobs/peekaboo_venv/bin/python3 /var/lib/jenkins/python_jobs/peekaboo.py --db_url=${env.db_url} --pki_password=${env.pki_client_cacert_password}"
)
}

相关内容

  • 没有找到相关文章

最新更新