Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import grails.plugins.rest.client.RestBuilder
- import grails.transaction.Transactional
- import sun.misc.BASE64Encoder
- @Transactional
- class JenkinsService {
- def grailsApplication
- def createJob(String folderName) {
- String url = grailsApplication.config.jenkins.url
- def rest = new RestBuilder(connectTimeout: 10000);
- def base1 = 'createItem?name='
- def base2 = '&mode=com.cloudbees.hudson.plugins.folder.Folder&from=&json=%7B%22name%22%3A%22'
- def base3 = '%22%2C%22mode%22%3A%22com.cloudbees.hudson.plugins.folder.Folder%22%2C%22from%22%3A%22%22%2C%22Submit%22%3A%22OK%22%7D&Submit=OK'
- def jobUrl = "${url}${base1}${folderName}${base2}${folderName}${base3}"
- def resp = rest.post(jobUrl) {
- auth getAuth()
- contentType "application/x-www-form-urlencoded"
- }
- println "Jenkins Job Creation response ${resp.text}"
- }
- private String getAuth() {
- String userName = grailsApplication.config.jenkinsrequest.jenkinsuser.username
- String password = grailsApplication.config.jenkinsrequest.jenkinsuser.password
- String userPassword = userName + ":" + password
- return "Basic " + (new BASE64Encoder().encode(userPassword.getBytes()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement