首页 > 解决方案 > 如何使用bitbucket repo上的Json文件在Jenkinsfile.groovy中传递环境变量?

问题描述

我正在寻找一种解决方案,以使用 Jenkinsfile.groovy 从 Json 文件中传递 Jenkins 管道中的环境变量。json 文件存在于 bitbucket 存储库中。

我的 json 文件:

{"id" : "11245" }

詹金斯文件:

stage('Execution') {
windowsNode = 'any'
    node(windowsNode) {
        checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'bitbucket-access', url:'http://stash.com']]])
   withEnv([def props = readJSON file: 'project.json', 'ID': 'props['id']']){
     stage('Build'){
       bat 'python --version' }
    echo 'executed'
     }
   }
}
 

但我收到错误:

java.lang.NullPointerException
at org.jenkinsci.plugins.workflow.steps.EnvStep.<init>(EnvStep.java:51)
Caused: java.lang.reflect.InvocationTargetException 

标签: jenkinsgroovyperformance-testingbitbucket-pipelines

解决方案


推荐阅读