Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import grails.plugins.rest.client.RestBuilder
  2. import grails.transaction.Transactional
  3. import sun.misc.BASE64Encoder
  4.  
  5. @Transactional
  6. class JenkinsService {
  7.  
  8. def grailsApplication
  9. def createJob(String folderName) {
  10. String url = grailsApplication.config.jenkins.url
  11. def rest = new RestBuilder(connectTimeout: 10000);
  12. def base1 = 'createItem?name='
  13. def base2 = '&mode=com.cloudbees.hudson.plugins.folder.Folder&from=&json=%7B%22name%22%3A%22'
  14. 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'
  15. def jobUrl = "${url}${base1}${folderName}${base2}${folderName}${base3}"
  16.  
  17. def resp = rest.post(jobUrl) {
  18. auth getAuth()
  19. contentType "application/x-www-form-urlencoded"
  20. }
  21.  
  22. println "Jenkins Job Creation response ${resp.text}"
  23.  
  24. }
  25.  
  26. private String getAuth() {
  27. String userName = grailsApplication.config.jenkinsrequest.jenkinsuser.username
  28. String password = grailsApplication.config.jenkinsrequest.jenkinsuser.password
  29. String userPassword = userName + ":" + password
  30. return "Basic " + (new BASE64Encoder().encode(userPassword.getBytes()));
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement