Reputation: 7887
Before accessing my SVN
repository, I need to create a tunnel
first like this :
ssh -L 9898:some_server.com:9898 user@another_server.com
After that, I am able to access the repository at port 9898
of my localhost
. While creating the Jenkins job, I can provide the SVN url as the localhost
, and Jenkins is able to access the repo, but I still have to manually create a tunnel on the server. Is there any way that I can automate that with Jenkins, so that if the access to the tunnel fails, then it can do the tunnelling, and try again ?
I am using Jenkins 1.487
Upvotes: 0
Views: 1965
Reputation: 27485
You need a plugin like pre-scm-buildstep
This allows you to execute build steps before the SVN checkout.
Using this, you can configure a step that would open the tunnel for you, before the SVN checkout begins.
However, I doubt SVN polling would work in such scenario.
Update:
Following OP questions, here is another possible solution:
https://wiki.jenkins-ci.org/display/JENKINS/ScriptTrigger+Plugin
I have not used it myself, but it allows a custom shell script to be executed instead of the regular polling. You can use this custom script to establish a tunnel first, and then poll for SVN changes. You would have to write up your own script for doing the actual SVN poll however. Something as simple as checking the workspace revision (svn info <LocalCheckOut>|grep Revision
) and checking it against the repository (svn info <URL>|grep Revision
). The plugin will allow you to schedule frequency of polls in cron format.
An alternative lazy way of doing it would be to use this plugin, establish the tunnel, do SVN update (whether there are changes or not), and then let the job build it. You can then have a regular build action that would detect if there was in fact new checkout or not, before the real build step.
Upvotes: 1
Reputation: 27485
Does your tunnel remain open on the server when you launch it with your script and the Jenkins jobs ends?
If so, and SVN polling is required, you have 2 possible solutions i can think of:
Create a separate job whose sole purpose it to run your script above. Schedule it to run every 2-3 minutes (or whatever your usual timeout on the tunnel is). This way hopefully you server will always have a tunnel open.
In your original job, use a conditional post-build step with this plugin:
https://wiki.jenkins-ci.org/display/JENKINS/Post+build+task
Parse log for SVN checkout failure, and if found:
2.1 Run your script to establish the tunnel
2.2 Relaunch your job again with curl
2.3 You can optionally use text-finder plugin to mark such builds as "unstable" rather than failed
https://wiki.jenkins-ci.org/display/JENKINS/Text-finder+Plugin
Upvotes: 1
Reputation: 7887
I added the plugin as specified by Slav
in the above answer, and wrote the following script in the section Run buildstep before SCM runs
:
instance_count=`ps x | grep -c 'ssh -L 9898:some_server.com:9898 user@another_server.com'`
if test $instance_count -lt 2 #two instances mean that one is of grep and other is the tunnel
then
ssh -L 9898:some_server.com:9898 -t -t user@another_server.com&
fi
With that, whenever I clicked on 'Build now
', the tunnel was first created, update checked in, and build completed. But, unfortunately, polling doesn't work in this case
Upvotes: 0