Create Jenkins job automatically

260 views
Skip to first unread message

songo...@gmail.com

unread,
Feb 19, 2017, 9:56:56 AM2/19/17
to job-dsl-plugin


First I would like to thank the people who've developed this excellent plug-in.

 I'm very new to groovy world so pls. bear if my question sounds silly.

Following DSL snippet, creates job based on the branches on SVN repository, my query is, will it be creating all the jobs  for all the branches available on the repo, every time or checks only for the new branches and create the associated jobs.

My requirement is to check or poll  only for the new branches created on the repo and create the corresponding jobs accordingly and ignore the previous available branches.

svnCommand = "svn list --xml svn://url_path/branches"
def proc = svnCommand.execute()
proc
.waitFor()
def xmlOutput = proc.in.text


def lists = new XmlSlurper().parseText(xmlOutput)
def listOfBranches = lists.list.entry.name


println
"Start making jobs ..."

Would be really grateful for any suggestions . Thanks.


Daniel Spilker

unread,
Feb 20, 2017, 11:19:55 AM2/20/17
to job-dsl...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugin+unsubscribe@googlegroups.com.
To post to this group, send email to job-dsl-plugin@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/5260fa90-3e12-40d3-b7f7-ffac5216d005%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

steven...@gmail.com

unread,
Feb 27, 2017, 9:41:20 AM2/27/17
to job-dsl-plugin
rather than use the SVN CLI and parse output - there's a java library for interacting with SVN.

@Grab(group='org.tmatesoft.svnkit', module='svnkit', version='1.8.4')
import org.tmatesoft.svn.core.SVNURL
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory
import org.tmatesoft.svn.core.io.SVNRepositoryFactory
import org.tmatesoft.svn.core.wc.SVNWCUtil

url = "your_url"
name="jenkins"
password="jenkins123"

DAVRepositoryFactory.setup()
repo = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url))
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(name,password)
repo.setAuthenticationManager( authManager )

def dirs = ["trunk"]
["branches","tags"].each{ dir ->
entries = repo.getDir(dir, -1, null, (Collection) null)
entries.each{ dirs.push(it) }
}

println dirs

This'll get you all your branches.  

For use in Jenkins you'll have to remove the @Grab and instead have the library jars available in the workspace to be added to the JobDSL Class Path in the Build Step configuration.
Reply all
Reply to author
Forward
0 new messages