Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将jenkins变量传递到管道文件中的作业dsl脚本_Jenkins_Jenkins Pipeline_Jenkins Job Dsl - Fatal编程技术网

将jenkins变量传递到管道文件中的作业dsl脚本

将jenkins变量传递到管道文件中的作业dsl脚本,jenkins,jenkins-pipeline,jenkins-job-dsl,Jenkins,Jenkins Pipeline,Jenkins Job Dsl,问题 如何将变量传递给内嵌在管道文件中的作业dsl脚本。我有一个Jenkins管道,它设置了一些变量,我想在管道中的pipelineJob模板中使用这些变量。尝试了不同的组合,但似乎做不好。例如,下面是我的管道,它从用户那里获取输入,即git repo url pipeline { agent any parameters { string(name: 'repo_url', defaultValue: '') }

问题 如何将变量传递给内嵌在管道文件中的作业dsl脚本。我有一个Jenkins管道,它设置了一些变量,我想在管道中的pipelineJob模板中使用这些变量。尝试了不同的组合,但似乎做不好。例如,下面是我的管道,它从用户那里获取输入,即git repo url

    pipeline {
   agent any

           parameters {
            string(name: 'repo_url', defaultValue: '')
        }

   stages {
      stage('Input gathering') {
         steps {
             script {
                            env.repo_url = input message: 'Enter github url', parameters: [string(defaultValue: '', description: '', name: 'repo_url', trim: false)]

             }
             echo "====${env.repo_url}======"
         }
      }
              stage('stage'){
            steps {
                // some other steps
                echo "====${env.repo_url}======"

                jobDsl scriptText: '''pipelineJob(\'new-job\') {


                    triggers {
                        scm(\'H/5 * * * *\')
                    }

                    definition {
                        cpsScm {
                            scm {
                                git {
                                    remote { 
                                        url(repo_url) 
                                        credentials('bitbucket-jenkins-access')
                                    }
                                    branches(\'master\')
                                    scriptPath(\'Jenkinsfile\')
                                    extensions { } 
                                }
                            }
                        }
                    }
                }'''                    
            }           
        }
    }
   }