Trigger Hudson builds on SVN commit

I have already set up a version control system (Subversion), which will be used by developers to fix and update their code (let's say its address is https://server/svn/project ). Only authorized users will be able to access the SVN project.

On the other hand, I installed Hudson as the project continuous integration server (project address is server:8080/job/project ).

I would like to achieve the following:

  • Hudson assemblies start automatically when there is an SVN commit.
  • Emails are sent to the appropriate developers (those who fixed the code) when their fixed code is not generated, which means that when user A captures a code that is not collected, only user A receives an email containing a notification.

I have set up matrix-based authorization for Hudson users because I don't want to be open to anyone.

I saw some suggestions for post-commit hooks, but none of them have worked so far.

Can someone tell me what to do regarding both issues? Concrete steps will be appreciated.

+11
svn build hudson
Jan 25 2018-11-11T00:
source share
4 answers

According to Building a Software Project # Builds by Changes in Subversion / CVS , Hudson needs to poll your SVN repo to detect changes and starts the build.

However, this can be triggered with every commit from SVN, for example in this thread .
The official script is on the Subversion Plugin page.

 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/hudson/subversion/${UUID}/notifyCommit?rev=$REV 

But it is indicated:

To do this, your Hudson must allow anonymous read access to the system .
If access control for your Hudson is more restrictive, you may need to provide a username and password , depending on your authentication settings.

+7
Jan 25 '11 at 11:44
source share

To initiate a build when there is a commit in SVN, you must (1) set your hudson job for remote creation and (2) make an SVN hook ...

the first part is pretty simple ... to make hook go to / var / lib / svn // hooks and rename post-commit.tmpl to post fix there you can do something like

 #!/bin/bash # Este script comprueba si se han hecho cambios en un directorio concreto, # y en tal caso lanza una build en Jenkins REPOS="$1" REV="$2" JENKINS_JOB="$3" JENKINS_USER=admin JENKINS_PASSWORD=**** JENKINS_HOST=<hostname> if [ -n $(svnlook dirs-changed $REPOS --revision $REV | fgrep "tags\/") ];then wget --quiet --auth-no-challenge --no-check-certificate --http-user=$JENKINS_USER --http-password=$JENKINS_PASSWORD http://$JENKINS_HOST/job/$JENKINS_JOB/build?token=TOKEN fi exit 0 

Have a look at this article http://blogsyntagma.blogspot.com.ar/2012/04/hook-de-subversion-para-ejecutar-un-job.html (this is in Spanish)

+4
Apr 10 2018-12-12T00:
source share

Here are the required steps:

  • Create an SVN user that Hudson can use to read-only access your repository.
  • Configure Hudson to use this SVN user when accessing the repository
  • Create a new task to use the repository at the specified address (i.e. to a specific branch)
  • Set up your task to poll the repository at least once per minute for any changes.
  • Customize your work to create the necessary
  • Configure your job to send email when build fails

I would recommend emailing all developers so that they are notified that the build is unstable, not just the culprit. Not only does this provide greater visibility, but it motivates the culprit to immediately fix the problem or otherwise take a curse from his fellow developers. Believe me, it is effective.

+1
Jan 25 '11 at 17:34
source share

This is how I got Jenkins 2.157 to start building after committing to the SVN repository.

1. Allow read access in Jenkins

Using the Jenkins web interface, go to Manage Jenkins Configure Global Security and select the " Allow anonymous read access :

allow anonymous read access screenshot

If you skip this step, you will receive the following response when you try to start the assembly using the HTTP request (described in the third step):

 Authentication required <!-- You are authenticated as: anonymous Groups that you are in: Permission you need to have (but didn't): hudson.model.Hudson.Read ... which is implied by: hudson.security.Permission.GenericRead ... which is implied by: hudson.model.Hudson.Administer --> 

2. Configure your build trigger

From the Jenkins web interface, go to the build task and determine that you want to run the assembly using a script (this will be the SVN commit hook in the next step):

configure build trigger

3. Create a post-commit hook

Finally, go to the hooks directory of the repository and add a shell script called post-commit (the name is important, otherwise SVN will not execute it after the commit):

 #!/bin/sh # Name of the Jenkins build job yourJob="your_job" # You defined this in Jenkins' build job build_token="yourSecretToken" jenkins_address_with_port="localhost:8090" curl $jenkins_address_with_port/job/$yourJob/build?token="$build_token" 

Make the script executable: chmod +x post-commit .




Here's an extended version of post-commit that logs post-commit information, such as the author of a commit.

 #!/bin/sh # The path to this repository repo_path="$1" # The number of the revision just committed rev="$2" # The name of the transaction that has become rev transaction_name="$3" # See http://svnbook.red-bean.com/en/1.7/svn.ref.svnlook.c.author.html commit_author="$(svnlook author --revision $rev $repo_path)" # The UUID of the repository, something like e3b3abdb-82c2-419e-a100-60b1d0727d12 repo_uuid=$(svnlook uuid $repo_path) # Which files were changed, added, or deleted. For example: # U src/main/java/com/bullbytes/MyProgram.java what_has_changed=$(svnlook changed --revision $rev $repo_path) log_file=/tmp/post_commit.log echo "Post-commit hook of revision $rev committed by $commit_author to repo at $repo_path with ID $repo_uuid was run on $(date). Transaction name: $transaction_name. User $(whoami) executed this script. This has changed: $what_has_changed" >> $log_file # Name of the Jenkins build job yourJob="your_job" # You defined this in Jenkins' build job build_token="yourSecretToken" jenkins_address_with_port="localhost:8090" curl $jenkins_address_with_port/job/$yourJob/build?token="$build_token" 

To learn more about commits, go to the documentation .

0
Jan 14 '19 at 16:56
source share



All Articles