【发布时间】:2019-08-15 14:45:44
【问题描述】:
我正在尝试在我的 serverless.yml 文件中引用在我的 jenkinsfile 中设置的变量。
在 jenkinsfile 我有这个
environment {
HELLO = 'hello-world'
}
在 serverless.yml 文件中我有这个
custom:
secret: ${env:HELLO}
运行 jenkins 管道时出现此错误
A valid environment variable to satisfy the declaration 'env:HELLO' could not be found.
这是我要求的完整 jenkins 文件,最终目标是我想使用 val1 和 val2 以及 env 变量,但如果我能弄清楚如何使用 hello world,那就是一回事了。
import com.lmig.intl.cloud.jenkins.exception.BuildException
def getJobName() {
return env.JOB_NAME
}
environment {
HELLO = 'hello-world'
}
def getEnvironment() {
def jobName = getJobName().split('/')
def environment = jobName[1].toLowerCase()
return environment.toLowerCase()
}
node('linux'){
stage('Checkout'){
checkout scm
}
stage('Pull Secrets From Vault'){
withAWS(credentials:'aws-cred'){
def secret = vaultPullSecrets(app:"sls-auxiliary-service",appenv:"nonprod",runtime:'nonprod',keys:'["saslusername","saslpassword"]')
def val1 = new groovy.json.JsonSlurper().parseText(secret)[0].SASLUSERNAME
def val2 = new groovy.json.JsonSlurper().parseText(secret)[1].SASLPASSWORD
if(val1 != '' && val2 != ''){
echo "Vault Secret pulled Successfully"
}else{
echo "Vault Secret Not Found"
throw new BuildException("Vault Secret Not Found")
}
}
}
stage('Deploy') {
def ENVIRONMENT = getEnvironment().replaceAll("\\_","")
withAWS(credentials:'aws-cred') {
sh 'npm i serverless-python-requirements'
sh 'npm install --save-dev serverless-step-functions'
sh 'npm install serverless-deployment-bucket --save-dev'
sh 'npm i serverless-pseudo-parameters'
sh 'npm i serverless-plugin-resource-tagging'
sh 'pip3 install --user -r requirements.txt'
sh "serverless deploy --stage ${ENVIRONMENT}"
}
}
}
【问题讨论】:
-
请分享您的 Jenkinsfile。我们需要知道 yaml 文件已经存在于您的源代码中或在作业运行期间创建。
-
@yong 添加了 jenkins 文件,serverless.yml 文件已经存在于我的源代码中,如果这就是你的意思吗?
-
对不起@yong 那是我搞砸的事情,你可以忽略它,没有意识到我仍然在代码中,现在正在编辑问题。它应该只是我要引用的字符串
-
对不起,我弄错了。
-
关于如何访问它的任何想法?
标签: amazon-web-services jenkins lambda environment-variables serverless