Jenkins管道中的GIT URL [英] GIT URL in Jenkins pipeline

查看:537
本文介绍了Jenkins管道中的GIT URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对Jenkins管道进行参数化.唯一的输入参数将是GITHUB_URL.我有一个Jenkinsfile作为回购协议的一部分.我想在管道配置中使用此变量(定义为参数)作为存储库URL".如何访问该参数?

I am trying to parameterize a Jenkins pipeline. The only input parameter will be GITHUB_URL. I have a Jenkinsfile as a part of the repo. I want to use this variable (defined as parameter) in my pipeline configuration as "Repository URL". How can I access the parameter ?

我尝试了$ GITHUB_URL,$ {GITHUB_URL}和$ {params.GITHUB_URL}.没有运气

I have tried $GITHUB_URL, ${GITHUB_URL} and ${params.GITHUB_URL}. No luck

还有其他建议吗?

推荐答案

因为您告诉您git repo中有一个jenkinsfile,我想您并不是要使用共享库中的参数来调用Jenkinsfile.

Because you are telling you have a jenkinsfile inside your git repo I suppose you do not mean that you want to call a Jenkinsfile using parameters from a shared library.

也不确定您使用的是声明性管道还是脚本化管道. 我将解释推荐的"声明性管道:

It's also not sure if you are using a declarative or scripted pipeline. I will explain the "recommended" declarative pipeline:

pipeline {
    agent any


    parameters { 
        string(defaultValue: "https://github.com", description: 'Whats the github URL?', name: 'URL')
    }


    stages {
        stage('Checkout Git repository') {
           steps {
                git branch: 'master', url: "${params.URL}"
            }
        }

        stage('echo') {
           steps {
                echo "${params.URL}"
            }
        }
    }
}

在此管道中,您将添加一个字符串参数,您可以在其中添加URL.当您运行构建时,它将要求输入参数:

In this pipeline you will add a string parameter to which you can add a URL. When you run the build it will ask for the parameter:

要使用此参数,请使用"${params.URL}": 该管道将​​在第一个阶段克隆github存储库,并在下一个(回显)阶段​​打印URL:

To use this parameter use "${params.URL}": This pipeline will clone the github repo in the first stage and print the URL in the next (echo) stage:

[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (echo)
[Pipeline] echo
https://github.com/lvthillo/docker-ghost-mysql.git
[Pipeline] }

这篇关于Jenkins管道中的GIT URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆