Jenkins notifyCommit trigger not working?

I have been working on this issue for several hours and it seems like I'm doing something wrong.

Firstly, the svn post-commit hook is already working, since I can already see the log, here is the code for post-commit:

#!/bin/sh REPOS="$1" REV="$2" UUID=`svnlook uuid $REPOS` /bin/echo "$REPOS $REV $UUID" >> /var/subversion/svn-post-commit.out 

Please note that for it to work, you need to run chmod 777 for post-fixing and run chown www-data: www-data in the svn repository.

What doesn't work is jenkins notifyCommit, which will automatically create a project in jenkins:

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

I also tried calling through curl

 curl --data "rev=4" http://localhost:8080/subversion/c8bb87ec-9a19-4975-ab9d-8b15741e6d7e/notifyCommit 

There are no errors, but jenkins did not build.

Any ideas?

curl reply:

 * About to connect() to 10.1.1.133 port 8080 (#0) * Trying 10.1.1.133... connected > POST /subversion/c8bb87ec-9a19-4975-ab9d-8b15741e6d7e/notifyCommit HTTP/1.1 > User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3 > Host: 10.1.1.133:8080 > Accept: */* > Content-Length: 5 > Content-Type: application/x-www-form-urlencoded > * upload completely sent off: 5out of 5 bytes < HTTP/1.1 200 OK < Server: Winstone Servlet Engine v0.9.10 < Connection: Close < Content-Type: text/html;charset=UTF-8 < Date: Mon, 22 Oct 2012 05:48:49 GMT < X-Powered-By: Servlet/2.5 (Winstone/0.9.10) < * Closing connection #0 

Thanks,
czetsuya

+4
source share
3 answers

I found a job, but it is not elegant. I used jenkins cli to call the assembly manually. I documented what I did here:

http://czetsuya-tech.blogspot.com/2012/10/an-alternative-way-of-invoking-jenkins.html .

0
source

There are two methods to run the assembly remotely in Jenkins, which I have successfully used. (Examples for shell script)

One of them is using the URL and start PARTIAL OPERATION:

Method 1:

 WGET="/usr/bin/wget" JENKINS_JOB="Your-Job-Name" $WGET http://ip:port/job/$JENKINS_JOB/build?token=sampletocken 

If you are trying to run a task parameterized, you can specify the parameters this way (otherwise the task will not start):

 $WGET http://ip:port/job/$JENKINS_JOB/buildWithParameters?param-name=param-value&token=sampletocken 

The token part = sampletocken is not required, but it adds a bit of security. You can configure the token in your work configuration in the "Trigger assemblies remotely" section.

Another method is to use the Jenkins disruptive API:

Method 2:

 # REPOS is the local path of the repository. # REV is the revision that we want to build. # SERVER is the full URL of Jenkins. # UUID of the repository (it will be used to identify it to Jenkins) REPOS="$1" REV="$2" SERVER="http://ip:port" UUID=`svnlook uuid $REPOS` $WGET \ --header "Content-Type:text/plain;charset=UTF-8" \ --post-data "`svnlook changed --revision $REV $REPOS`" \ --output-document "-" \ --timeout=2 \ $SERVER/subversion/${UUID}/notifyCommit?rev=$REV 

For all this to work, you had to grant the rights to an anonymous user in Jenkins. However, this may be something you do not want to do, as this causes security problems.

Authentication

To make it more secure, you can create a separate user that will be used in the script to authenticate Jenkins. Configure this user to have an "API tag" that you intend to use in the script. (do not forget to remove all rights for an anonymous user)

Then you need to add the following to the wget command:

 wget --auth-no-challenge --http-user=user --http-password=apiToken 

"-auth-no-challenge" is used to avoid the "403 forbidden" error. You can also add another token to the URL, as in the previous example.

This last part was problematic for me, so it could go through trial and error ...

+4
source

If you want to remotely run Jenkins assemblies remotely, you need to select trigger assemblies remotely (for example, from scripts) in the Build Triggers section of the job. When you do this, you will give him a token, which must be transferred to the Jenkins project.

For example, if your build token is BUILD , you must pass

 http://<JenkinsURL>/job/<jobName>/build?token=BUILD 

I have done a lot with CVS because CVS will take too long and require too many resources for Jenkins to find out if a commit has occurred. CVS had to go through every file in the project to find out if there was an update. I usually don’t do this with Subversion, because Subversion can instantly see if or not there was a change in the repository, and this check takes up very few resources.

+2
source

Source: https://habr.com/ru/post/1441174/


All Articles