使用POST COMMIT钩子在SVN存储库上提交代码时,Jenkins作业自动触发 [英] Jenkins job auto-triggering when code commit on SVN repo using POST COMMIT hook

查看:322
本文介绍了使用POST COMMIT钩子在SVN存储库上提交代码时,Jenkins作业自动触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Jenkins,docker和Ansible实现CI/CD管道.我正在将SVN代码存储库用于我的版本控制系统.对于部署和SVN代码存储库,我使用的是AWS EC2.部署和代码存储库位于单独的VM中.

I am trying to implement CI/CD pipeline using Jenkins , docker and Ansible. I am using SVN code repository for my version control system. For deployment and SVN code repo, I am using AWS EC2. Deployment and code repo is in separate VM.

我的要求

当我将代码提交到SVN存储库中时,我需要触发一个Jenkins Job.该工作将被称为ansible playbook,稍后将构建项目,构建Docker映像并将其部署到EC2中.因此,对于我的SVN代码存储库的任何更改,我需要构建Jenkins作业.

When I am committing my code into SVN repository , I need to trigger one Jenkins Job. That job will call a ansible playbook.Later it will build project, build Docker image and deploy into EC2. So for any change to my SVN code repository, I need to build Jenkins job.

我当前的尝试

我在$ repo/hooks文件夹下的post-commit.tmpl文件中添加了以下脚本.

I added the following script in post-commit.tmpl file under $repo/hooks folder.

REPOS="$1"
REV="$2"
UUID=`svnlook uuid $REPOS`
/usr/bin/wget \
  --header "Content-Type:text/plain;charset=UTF-8" \
  --post-data "`svnlook changed --revision $REV $REPOS`" \
  --output-document "-" \
  --timeout=2 \
  http://server/subversion/${UUID}/notifyCommit?rev=$REV

以下是屏幕截图

并选中"Jenkins Job中的投票SCM选项":

And checked the "Poll SCM option in Jenkins Job":

注意::我不是要从回购中抽出分钟/小时/周的时间表.取而代之的是,我正在寻找代码更改的时间,然后我需要构建Jenkins项目.所以我没有添加任何时间表.

NB: I am not looking minute/hours/week schedule to pull from repo. Instead of that, I am looking when there is a code change, then I need to build Jenkins project. So I did not add any schedule.

但是我仍然没有得到Jenkins的最新代码.如何找出与我的配置有关的问题?

But still I am not getting the latest code in Jenkins. How can I find out the issue related with my configuration?

已更新的post-commit.tmpl文件

推荐答案

我做了很多尝试,通过使用答案中的指导来解决此问题.最终,我得到了我所面临的实际问题.我在文件"post-commit.tmpl"中添加了提交后脚本.创建我的SVN信息库时默认获得此文件.无需添加"post-commit.tmpl",只需创建文件"post-commit"即可.它解决了我的问题.

I made lot attempt to resolve this problem by using guidance from answers. Finally I got the actual issue that I was facing. I added the post-commit script in the file "post-commit.tmpl". This file defaulty I got when I created my SVN repository. Instead of adding the "post-commit.tmpl" need to create file just "post-commit". It resolved my problem.

这篇关于使用POST COMMIT钩子在SVN存储库上提交代码时,Jenkins作业自动触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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