如何通过 Jenkinsfile 将环境变量传递给 openshift
How to pass an Environment variable to openshft via Jenkisfile
我有这个 Jenkinsfile
pipeline {
agent any
tools {
maven 'maven381'
jdk 'JDK904'
oc 'oc'
}
parameters {
string(name:'CLUSTER_NAME',defaultValue:'openshift-cluster',description:'Cluster name space')
string(name:'PROJECT_NAME',defaultValue:'etias-sword-dev',description:'Cluster project name')
}
stages {
stage('Build') {
steps {
script {
openshift.withCluster(CLUSTER_NAME) {
openshift.withProject(PROJECT_NAME) {
openshift.newApp('--image-stream="openshift/java:11"~https://github.com/filip123go/Simplest-Spring-Boot-Hello-World.git --env=MAVEN_OPTS=-Dhttps.protocols=TLSv1.2')
}
}
}
}
}
}
}
我想传入环境变量
MAVEN_OPTS=-Dhttps.protocols=TLSv1.2
所以每次我 运行 Jenkins 中的作业时,环境变量都会自动通过。
我知道openshift中的cli命令是
oc set env bc simplest-spring-boot-hello-world
MAVEN_OPTS=-Dhttps.protocols=TLSv1.2
我已经试过了,没有成功
openshift.newApp('--image-stream="openshift/java:11"~https://github.com/filip123go/Simplest-Spring-Boot-Hello-World.git --env=MAVEN_OPTS=-Dhttps.protocols=TLSv1.2')
和
openshift.newApp('--image-stream="openshift/java:11"~https://github.com/filip123go/Simplest-Spring-Boot-Hello-World.git
--param=MAVEN_OPTS=-Dhttps.protocols=TLSv1.2')
和
openshift.newApp('--image-stream="openshift/java:11"~https://github.com/filip123go/Simplest-Spring-Boot-Hello-World.git
MAVEN_OPTS=-Dhttps.protocols=TLSv1.2')
和
openshift.newApp('--image-stream="openshift/java:11"~https://github.com/filip123go/Simplest-Spring-Boot-Hello-World.git
-e=MAVEN_OPTS=-Dhttps.protocols=TLSv1.2')
没有成功。
你能帮忙吗?
经过大量实验(并通过阅读文档),这是在环境变量中传递的正确方法
openshift.newApp('--image-stream="openshift/java:11"~https://github.com/filip123go/Simplest-Spring-Boot-Hello-World.git --build-env MAVEN_OPTS=-Dhttps.protocols=TLSv1.2')
这是更新后的 Jenkins 文件:
pipeline {
agent any
tools {
maven 'maven381'
jdk 'JDK904'
oc 'oc'
}
parameters {
string(name:'CLUSTER_NAME',defaultValue:'openshift-cluster',description:'Cluster name space')
string(name:'PROJECT_NAME',defaultValue:'etias-sword-dev',description:'Cluster project name')
}
stages {
stage('Build') {
steps {
script {
openshift.withCluster(CLUSTER_NAME) {
openshift.withProject(PROJECT_NAME) {
openshift.newApp('--image-stream="openshift/java:11"~https://github.com/filip123go/Simplest-Spring-Boot-Hello-World.git --build-env MAVEN_OPTS=-Dhttps.protocols=TLSv1.2')
}
}
}
}
}
}
}
我有这个 Jenkinsfile
pipeline {
agent any
tools {
maven 'maven381'
jdk 'JDK904'
oc 'oc'
}
parameters {
string(name:'CLUSTER_NAME',defaultValue:'openshift-cluster',description:'Cluster name space')
string(name:'PROJECT_NAME',defaultValue:'etias-sword-dev',description:'Cluster project name')
}
stages {
stage('Build') {
steps {
script {
openshift.withCluster(CLUSTER_NAME) {
openshift.withProject(PROJECT_NAME) {
openshift.newApp('--image-stream="openshift/java:11"~https://github.com/filip123go/Simplest-Spring-Boot-Hello-World.git --env=MAVEN_OPTS=-Dhttps.protocols=TLSv1.2')
}
}
}
}
}
}
}
我想传入环境变量
MAVEN_OPTS=-Dhttps.protocols=TLSv1.2
所以每次我 运行 Jenkins 中的作业时,环境变量都会自动通过。 我知道openshift中的cli命令是
oc set env bc simplest-spring-boot-hello-world MAVEN_OPTS=-Dhttps.protocols=TLSv1.2
我已经试过了,没有成功
openshift.newApp('--image-stream="openshift/java:11"~https://github.com/filip123go/Simplest-Spring-Boot-Hello-World.git --env=MAVEN_OPTS=-Dhttps.protocols=TLSv1.2')
和
openshift.newApp('--image-stream="openshift/java:11"~https://github.com/filip123go/Simplest-Spring-Boot-Hello-World.git --param=MAVEN_OPTS=-Dhttps.protocols=TLSv1.2')
和
openshift.newApp('--image-stream="openshift/java:11"~https://github.com/filip123go/Simplest-Spring-Boot-Hello-World.git MAVEN_OPTS=-Dhttps.protocols=TLSv1.2')
和
openshift.newApp('--image-stream="openshift/java:11"~https://github.com/filip123go/Simplest-Spring-Boot-Hello-World.git -e=MAVEN_OPTS=-Dhttps.protocols=TLSv1.2')
没有成功。 你能帮忙吗?
经过大量实验(并通过阅读文档),这是在环境变量中传递的正确方法
openshift.newApp('--image-stream="openshift/java:11"~https://github.com/filip123go/Simplest-Spring-Boot-Hello-World.git --build-env MAVEN_OPTS=-Dhttps.protocols=TLSv1.2')
这是更新后的 Jenkins 文件:
pipeline {
agent any
tools {
maven 'maven381'
jdk 'JDK904'
oc 'oc'
}
parameters {
string(name:'CLUSTER_NAME',defaultValue:'openshift-cluster',description:'Cluster name space')
string(name:'PROJECT_NAME',defaultValue:'etias-sword-dev',description:'Cluster project name')
}
stages {
stage('Build') {
steps {
script {
openshift.withCluster(CLUSTER_NAME) {
openshift.withProject(PROJECT_NAME) {
openshift.newApp('--image-stream="openshift/java:11"~https://github.com/filip123go/Simplest-Spring-Boot-Hello-World.git --build-env MAVEN_OPTS=-Dhttps.protocols=TLSv1.2')
}
}
}
}
}
}
}