问题描述
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
来加载其他文件的方法来解决此问题
EDITYou 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!