jenkins管道从scm获取管道脚本下的存储库URL变量 [英] jenkins pipeline get repository url variable under pipeline script from scm

查看:86
本文介绍了jenkins管道从scm获取管道脚本下的存储库URL变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用位于git存储库中的Jenkins文件.我已经使用指向sjenkinsfile的scm的管道脚本配置了新作业.我试图在我的Jenkins文件管道脚本中使用git模块,以便从我的git存储库中提取数据,而无需配置pre静态变量,而只是使用已在scm中配置的scm在管道脚本下使用存储库URL的变量我的工作 .有一种方法可以获取变量存储库URL 从该插件中获取,而无需在我的Jenkins管道脚本中使用参数.

我已经尝试过环境变量 GIT_URL 和其他与

解决方案

您可以在 scm 变量中找到有关scm的所有信息(实例为结帐步骤

i'm using Jenkins file that located in my git repository. I have configured new job using the pipeline script from scm that point to my jenkinsfile. I'm trying to use in my Jenkins file pipeline script the git module in order to pull my data from my git repo without configure pre static variable and just to use the variable of the repository URL under pipeline script from scm that already was configured in my job . There is a way to get somehow the variable Repository URL from this plugin without using parameters in my Jenkins pipeline script.

I have already tried the environment variable GIT_URL and other stuff that related to git from here but this didn't work.

解决方案

You can find all information about scm in scm variable (instance of GitSCM if you are using git). You can get repository URL this way

def repositoryUrl = scm.userRemoteConfigs[0].url  

But if you just want to checkout that repository you can simply invoke checkout scm without needing to specify anything else. See checkout step

这篇关于jenkins管道从scm获取管道脚本下的存储库URL变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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