【问题标题】:How to pass an Environment variable to openshft via Jenkisfile如何通过 Jenkinsfile 将环境变量传递给 openshift
【发布时间】:2021-05-10 15:35:30
【问题描述】:

我有这个 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 simple-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')

没有成功。 你能帮忙吗?

【问题讨论】:

    标签: jenkins jenkins-pipeline openshift


    【解决方案1】:

    经过大量实验(并通过阅读文档),这是在环境变量内部传递的正确方法

    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')
                }
              }
            }
          }
        }
      }
    

    }

    【讨论】:

      猜你喜欢
      • 2020-07-26
      • 2020-03-05
      • 1970-01-01
      • 2021-11-27
      • 1970-01-01
      • 2019-01-07
      • 1970-01-01
      • 2013-12-29
      • 2016-07-08
      相关资源
      最近更新 更多