Jenkins Pipeline 动态指定 gitUrl 和 gitBranch

2022-03-18 14:04:27 浏览数 (1)

0. 本次只针对jenkins 流水线和多分支流水线的job类型讲解动态指定git的问题

在这里插入图片描述在这里插入图片描述

1. 错误的配置如下图

在这里插入图片描述在这里插入图片描述

执行报错

代码语言:java复制
15:29:43  Started by user admin
15:29:43  Rebuilds build #18
15:29:43  hudson.plugins.git.GitException: Command "git fetch --tags --progress --prune -- origin  refs/heads/master:refs/remotes/origin/master" returned status code 128:
15:29:43  stdout: 
15:29:43  stderr: fatal: '${PIPELINE_GIT_URL}' does not appear to be a git repository
15:29:43  fatal: Could not read from remote repository.
15:29:43  
15:29:43  Please make sure you have the correct access rights
15:29:43  and the repository exists.
15:29:43  
15:29:43  	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2450)
15:29:43  	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2051)
15:29:43  	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:84)
15:29:43  	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:573)
15:29:43  	at jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:365)
15:29:43  	at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:197)
15:29:43  	at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:173)
15:29:43  	at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:115)
15:29:43  	at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:69)
15:29:43  	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:309)
15:29:43  	at hudson.model.ResourceController.execute(ResourceController.java:100)
15:29:43  	at hudson.model.Executor.run(Executor.java:433)
15:29:43  Finished: FAILURE

2. 正确的配置如下图

在这里插入图片描述在这里插入图片描述

3.轻量级检查的名词解释

英文描述

If selected, try to obtain the Pipeline script contents directly from the SCM without performing a full checkout. The advantage of this mode is its efficiency; however, you will not get any changelogs or polling based on the SCM. (If you use checkout scm during the build, this will populate the changelog and initialize polling.) Also build parameters will not be substituted into SCM configuration in this mode. Only selected SCM plugins support this mode.

中文描述

如果选中,请尝试直接从SCM获取管道脚本内容,而不执行完全签出。这种模式的优点是效率高;但是,您不会得到任何基于SCM的变更日志或轮询。(如果在构建期间使用checkout scm,这将填充变更日志并初始化轮询。)在这种模式下,构建参数也不会被替换到SCM配置中。只有选定的SCM插件支持此模式。

0 人点赞