从jenkins的管道插件中的自定义位置选择JenkinsFile [英] Pick JenkinsFile from custom location in pipeline plugin of jenkins

查看:796
本文介绍了从jenkins的管道插件中的自定义位置选择JenkinsFile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jenkins管道插件可以从自定义位置选择jenkinsfile并开始构建吗?

Can jenkins pipeline plugin pick jenkinsfile from a custom location and start the build?

我不想将jenkinsfile保留在源代码中.源代码是否有任何更改.应该从自定义位置选择jenkinsfile并开始构建.

i don't want to keep jenkinsfile inside the source code. If there is any change in the source code. jenkinsfile from custom location should be picked and build should be started.

示例:/home/test/jenkinsfile

Example:/home/test/jenkinsfile

推荐答案

当然,只要用户有权阅读,就可以尝试放置自定义位置(我不明白为什么不能这样做)那个地点.

You can of-course just try to put a custom location (I wouldn't see why it can't) as long as the user has rights to read the location.

如果它是多分支管道,则比.由于索引基于Jenkinsfile的存在(仅对包含Jenkinsfile的分支进行索引)

If it is a multibranch pipeline, than no. Because indexing is based the presence of a Jenkinsfile (only branches that contain a Jenkinsfile are indexed)

在仓库中包含构建逻辑的想法是,它与源一起由源控制.当您更改源代码中的某些内容并影响构建时,构建特定的提交将具有所有逻辑.如果将此内容移出存储库,则构建逻辑和存储库很可能会不同步.

The thought behind having the logic of your build inside your repository is, that this is source controlled together with your sources. When you change something in your sources and this affects your build, than building that specific commit will have all the logic. If you move this outside your repository your build logic and your repository are very likely to get out of sync.

编辑 您可以通过添加Jenkinsfile来加载其他文件的方法来解决此问题

EDIT You can workaround this by adding a Jenkinsfile that will load the other file

Jenkinsfile:

Jenkinsfile:

load "/home/test/Jenkinsfile"

据我所知,目录是相对于工作区的.因此,如果您要使用的dir("path/to/other/dir"){..}相对于作业的工作空间要运行,则会使您的静态Jenkinsfile读取起来非常混乱.

However as far as I know, directoriees are relative to the workspace. So if you have any dir("path/to/other/dir"){..} than that will run relative to the workspace of the job, which makes your static Jenkinsfile very confusing to read.

这篇关于从jenkins的管道插件中的自定义位置选择JenkinsFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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