asp.net mvc - Jenkins trigger a build based on the commit in multiple projects -
recently have started working on ci project, has build project on scm commit (git/svn). tried using build trigger remotely , triggering job when commit code , building application successfully.
now have multiple projects in single repository, based on commit has find respective project in repository , start executing specific job.
is there way in jenkins?
code post-commit-hook-jenkins.vbs file
set args = wscript.arguments jobname = args.item(0) token = args.item(1) ' url open surl = "http://builduser:a844e9e505bfc5e6e9ce6e953ba5443a@localhost:8080/buildbytoken/build?job=" + jobname + "&token=" + token ' post request send. wscript.echo "surl: " + surl srequest = "" httppost surl, srequest function httppost(surl, srequest) set ohttp = createobject("microsoft.xmlhttp") ohttp.open "post", surl,false ohttp.setrequestheader "content-type", "application/x-www-form-urlencoded" ohttp.setrequestheader "content-length", len(srequest) ohttp.send srequest httppost = ohttp.responsetext end function
code post-commit.bat file
set cscript=%windir%\system32\cscript.exe set vbscript=e:\repositories\cicd\hooks\post-commit-hook-jenkins.vbs "%cscript%" "%vbscript%" "jobname" "authenticationtoken"
if you
- set svn/git location of project under "source code managment" section of job configuration
- and choose "poll scm" in "build triggers" section
then should work pretty want.
the fact asking question means doing source code checkout build script, right? avoid , instead let jenkins handle svn checkout/git clone.
or maybe trying avoid polling, , question how trigger different projects svn post-commit hook depending on in svn repository committed? in case need write more sophisticated hook script analyzes paths affected commit , triggers correct jenkins job(s) based on that.
edit:
in post-commit.bat file, should pass on repository , revision number of commit instead of job name, don't know yet job trigger. subversion passes repository , revision first , second argument.
set cscript=%windir%\system32\cscript.exe set vbscript=e:\repositories\cicd\hooks\post-commit-hook-jenkins.vbs set repos=%1 set revision=%2 "%cscript%" "%vbscript%" %repos% %revision% "authenticationtoken"
in .vbs script, should replace statement jobname taken argument by
repos = args.item(0) revision = args.item(1) token = args.item(2)
now need use revision number inspect changes svnlook.exe. put absolute path svnlook.exe in svnlook
variable , execute this:
set changedexec = shell.exec(svnlook & " changed --revision " & revision & " " & repos) until changedexec.stdout.atendofstream changed = changed + changedexec.stdout.readline() + chr(10) loop
now have output of svnlook.exe changed in changed
variable. tells files in svn repository affected commit.
next, parse content of changed
variable decide on job name trigger. example, simple check whether contains " foo/trunk/" , trigger foo-trunk job.
Comments
Post a Comment