Jenkins管道环境部分未连续执行
在执行jenkins管道环境部分时,我在jenkins环境部分遇到了一些问题Jenkins管道环境部分未连续执行,jenkins,jenkins-pipeline,openshift,Jenkins,Jenkins Pipeline,Openshift,在执行jenkins管道环境部分时,我在jenkins环境部分遇到了一些问题 import groovy.transform.Field @Field gitScriptPath = "https://raw.github.com/Innovation/" @Field clrInfo @Field gitlabMem @Field gitSubGroupURL @Field clrDuration @Field cloudProvider @Field userS
import groovy.transform.Field
@Field gitScriptPath = "https://raw.github.com/Innovation/"
@Field clrInfo
@Field gitlabMem
@Field gitSubGroupURL
@Field clrDuration
@Field cloudProvider
@Field userSpecData
@Field slackIntMes
pipeline {
agent { label 'master' }
environment {
GITHUB_TOKEN = credentials(' GITHUB_TOKEN')
GIT_URL = 'github.com/Innovation/exp-selling-iac.git'
PRE_PROV = 'k8s-jobs/iac_preprovision.yaml'
OS_PROV = 'k8s-jobs/iac_openshift.yaml'
USER_PROV = 'k8s-jobs/rhos-user-onboard-offboard.yaml'
ISTIO_PROV = 'k8s-jobs/iac_istio.yaml'
KAFKA_PROV = 'k8s-jobs/iac_kafka.yaml'
MONOLITH_PROV = 'k8s-jobs/iac_monolith.yaml'
POST_PROV = 'k8s-jobs/iac_postprovision.yaml'
DEVOPS_PROV = 'k8s-jobs/k8s_iac_devops.yaml'
dummy = sh ( script: '''echo "${USER_SPEC}" > userspec.yaml''', returnStdout: true )
NAMESPACE = sh ( script: "$JENKINS_HOME/custompath/yq r userspec.yaml Cluster.Name", returnStdout: true )
requestor = sh ( script: "$JENKINS_HOME/custompath/yq r userspec.yaml Cluster.Users.User1.ID", returnStdout: true ).trim()
APPOPS_ROLE = 'appops-customrole-v2'
}
stages {
stage('Download - Groovy Scripts'){
在这里,我们需要在执行虚拟后获得名称空间和请求者的值。
但是以dummy开头的行发生在名称空间和请求程序行之后。
同样的引语在早些时候也适用。如果我删除requestor=或APPOPS\u ROLE=则一切都会很好。请帮助了解这里发生了什么。
在我工作的过程中,我可以通过配置作业在jenkins中将APPOPS_角色作为参数。这也与变量的大小写有关。也就是说,如果我制造哑巴-->哑巴,它将产生影响。
詹金斯。2.204.2在openshift 3.11上,我不知道为什么排序未定义。可能分配首先存储在哈希表中,然后枚举哈希表,这将导致看似随机的顺序 作为一种解决方法,您可以将环境初始化移动到一个阶段,在该阶段中,您可以使用脚本块来确保执行顺序: 管道{ 代理{label'master'} 舞台{ 阶段“初始化”{ 台阶{ 剧本{ env.dummy=sh脚本:“echo${USER_SPEC}>userspec.yaml”,returnStdout:true env.NAMESPACE=sh脚本:$JENKINS_HOME/custompath/yq r userspec.yaml Cluster.Name,returnStdout:true env.requestor=sh脚本:$JENKINS_HOME/custompath/yq r userspec.yaml Cluster.Users.User1.ID,returnStdout:true.trim ... } } } 阶段“下载-Groovy脚本”{ ... } } }
谢谢@zetta42。我已经将APPOPS_ROLE='APPOPS-customrole-v2'作为jenkins参数配置作业,问题已经解决。不确定您提供的变通方法是否可以在管道中的shell脚本中使用。我更想了解为什么命令不能在环境部分按顺序执行。你的变通方法对我面临的另一个问题真的很有帮助。ie im无法在shell脚本中使用管道变量,如果它没有以env作为前缀定义。我已经测试了您的工作环境,并且变量也在shell脚本中工作。