git Jenkins - 不要为特定的提交者或提交消息构建

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33981607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:34:35  来源:igfitidea点击:

Jenkins - Dont build for specific commiter or commit message

gitjenkinscontinuous-integrationbuild-process

提问by Nick Tsitlakidis

I'm having some issues with Jenkins and its Git plugin.

我在使用 Jenkins 及其 Git 插件时遇到了一些问题。

Currently, a Gitlab server is triggering the builds but I want to configure the job so that it doesn't build when a specific message is included in the commit.

目前,Gitlab 服务器正在触发构建,但我想配置该作业,以便在提交中包含特定消息时不会构建它。

I've tried using the ci-skip plugin (https://github.com/banyan/jenkins-ci-skip-plugin) but instead of not starting the job, the plugin allows it to start but then aborts it.

我试过使用 ci-skip 插件 ( https://github.com/banyan/jenkins-ci-skip-plugin) 但不是不开始工作,插件允许它启动但然后中止它。

It does the job but I'm having aborted builds in Jenkins history and I'm trying to avoid that.

它完成了这项工作,但我已经中止了 Jenkins 历史中的构建,我正试图避免这种情况。

Anyone managed to do that?

有人设法做到了吗?

回答by mainframer

Jenkins git plugin itself already provides these kinds of advanced usage.

Jenkins git 插件本身已经提供了这些高级用法。

Exclude specific messages

排除特定消息

Job config page -->Source Code Management-->Git-->Add -->Polling ignores commits with certain messages

作业配置页面 --> 源代码管理 --> Git --> 添加 --> 轮询忽略带有某些消息的提交

Exclude specific commiters

排除特定提交者

Job config page -->Source Code Management-->Git-->Add -->Polling ignores commits from certain users

作业配置页面-->源代码管理-->Git-->添加-->轮询忽略来自某些用户的提交

Don't forget to click the help at the end of each of them to learn the correct way of usage.

不要忘记点击每一个末尾的帮助来学习正确的使用方法。

回答by Clerenz

If you have not yet found a solution:

如果您还没有找到解决方案:

  1. Configure your job to poll SCM but do not enter a timeplan for that (ignoring the warning that your job would never run.

  2. Configure the scm section to ignore commits, users, etc.

  3. Use a trigger for your jobs as follows: http://yourserver/git/notifyCommit?url=<URL of the Git repository>[&branches=branch1[,branch2]*][&sha1=<commit ID>]as seen on Git Plugin page

  1. 将您的作业配置为轮询 SCM,但不要为此输入时间计划(忽略您的作业永远不会运行的警告。

  2. 配置 scm 部分以忽略提交、用户等。

  3. 为您的作业使用触发器,如下所示:http://yourserver/git/notifyCommit?url=<URL of the Git repository>[&branches=branch1[,branch2]*][&sha1=<commit ID>]Git 插件页面所示

Whenever the URL is called, jenkins will scan for jobs that are using this repository. Then it checks for any specific settings (e. g. ignoring commits by certain users or with some commit messages) and either run the build or not. Of course the build will always somehow start to poll scm and check for commits, but if it is cancelled due to unimportant commits you will not see an aborted build in your history.

每当调用 URL 时,jenkins 将扫描使用此存储库的作业。然后它检查任何特定的设置(例如,忽略某些用户的提交或某些提交消息)并运行或不运行构建。当然,构建总是会以某种方式开始轮询 scm 并检查提交,但是如果由于不重要的提交而被取消,您将不会在历史记录中看到中止的构建。

回答by CodeWizard

You will need to use external script.

您将需要使用外部脚本。

Pull out the project (git clone/fetch) and then before continuing with your build check to see if the specific message is in your repository.

拉出项目 (git clone/fetch),然后在继续构建之前检查特定消息是否在您的存储库中。

To check to see if your message is there you can use the git show or git log commands.

要检查您的消息是否存在,您可以使用 git show 或 git log 命令。

git log

混帐日志

git log --all --grep='<your message>'
# and you can add more flags if you want of course:
git log --all --oneline | grep '<your message>'

git grep

混帐

git grep '<your message>' $(git rev-list --all)


Outside of Jenkins

詹金斯之外

Add code to git hookwhich check what you want to find *messages, commit etc) and only if it find it call Jenkins via REST API and start your job.

添加代码以git hook检查您想要查找的内容 *messages、commit 等),并且仅当它找到它时才通过 REST API 调用 Jenkins 并开始您的工作。

This is the way im using Jenkins, i check for something that i looking for and then im invoking Jenkins via API

这是我使用 Jenkins 的方式,我检查我正在寻找的东西,然后我通过 API 调用 Jenkins

Read more here& here

在这里这里阅读更多