.cico.pipeline 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import groovy.json.JsonOutput
  2. def notifyPagurePR(repo, msg, status, credentials = 'pagure-auth'){
  3. def json = JsonOutput.toJson([name: 'pagure', url: env.JOB_NAME, build: [full_url: currentBuild.absoluteUrl, status: status, number: currentBuild.number]])
  4. println json
  5. withCredentials([string(credentialsId: credentials, variable: "PAGURE_PUSH_SECRET")]) {
  6. /* We need to notify pagure that jenkins finished but then pagure will
  7. wait for jenkins to be done, so if we wait for pagure's answer we're
  8. basically stuck in a loop where both jenkins and pagure are waiting
  9. for each other */
  10. sh "timeout 1 curl -X POST -d \'$json\' https://pagure.io/api/0/ci/jenkins/$repo/${PAGURE_PUSH_SECRET}/build-finished -H \"Content-Type: application/json\" | true"
  11. }
  12. }
  13. def onmyduffynode(script){
  14. ansiColor('xterm'){
  15. timestamps{
  16. sh 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root ${DUFFY_NODE}.ci.centos.org -t \"export REPO=${REPO}; export BRANCH=${BRANCH};\" "' + script + '"'
  17. }
  18. }
  19. }
  20. def syncfromduffynode(rsyncpath){
  21. sh 'rsync -e "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root " -Ha --include=' + rsyncpath + " ${DUFFY_NODE}.ci.centos.org:~/ ./"
  22. }
  23. node('pagure') {
  24. properties([
  25. parameters([
  26. string(defaultValue: "", description: "", name: "REPO"),
  27. string(defaultValue: "", description: "", name: "BRANCH"),
  28. ])
  29. ])
  30. stage('Allocate Node'){
  31. env.CICO_API_KEY = readFile("${env.HOME}/duffy.key").trim()
  32. duffy_rtn=sh(
  33. script: 'cico --debug node get -f value -c hostname -c comment',
  34. returnStdout: true
  35. ).trim().tokenize(' ')
  36. env.DUFFY_NODE=duffy_rtn[0]
  37. env.SSID=duffy_rtn[1]
  38. env.BRANCH=params.BRANCH
  39. env.REPO=params.REPO
  40. }
  41. try {
  42. stage('Pre Setup Node'){
  43. // Install EPEL
  44. onmyduffynode 'yum -y install epel-release git'
  45. }
  46. stage('Clone Test Suite') {
  47. onmyduffynode "git clone --single-branch --depth 1 https://pagure.io/pagure.git"
  48. }
  49. stage('Run Test Suite') {
  50. timeout(time: 6, unit: 'HOURS') {
  51. onmyduffynode 'cd pagure && sh ./run_ci_tests.sh'
  52. }
  53. }
  54. } catch (e) {
  55. currentBuild.result = "FAILURE"
  56. throw e
  57. } finally {
  58. stage('Sync Artifacts'){
  59. syncfromduffynode('pagure/*.out')
  60. }
  61. stage('Deallocate Node'){
  62. sh 'cico node done ${SSID}'
  63. }
  64. stage('Notify PR'){
  65. res = currentBuild.currentResult
  66. notifyPagurePR("pagure", "Build " + res + "! ", res)
  67. }
  68. stage('Archive Artifacts'){
  69. archiveArtifacts artifacts: 'pagure/*.out'
  70. }
  71. }
  72. }