.cico.pipeline 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import groovy.json.JsonOutput
  2. def notifyPagurePR(repo, msg, status, phase, credentials = 'pagure-auth'){
  3. def json = JsonOutput.toJson([name: 'pagure', url: env.JOB_NAME, build: [full_url: currentBuild.absoluteUrl, status: status, number: currentBuild.number, phase: phase]])
  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('Notify PR'){
  47. notifyPagurePR("pagure", "Tests running ", "BUILDING", "STARTED")
  48. }
  49. stage('Clone Test Suite') {
  50. onmyduffynode "git clone --single-branch --depth 1 https://pagure.io/pagure.git"
  51. }
  52. stage('Run Test Suite') {
  53. timeout(time: 6, unit: 'HOURS') {
  54. onmyduffynode 'cd pagure && sh ./run_ci_tests.sh'
  55. }
  56. }
  57. } catch (e) {
  58. currentBuild.result = "FAILURE"
  59. throw e
  60. } finally {
  61. stage('Sync Artifacts'){
  62. syncfromduffynode('pagure/results-py2/')
  63. syncfromduffynode('pagure/results-py3/')
  64. }
  65. stage('Deallocate Node'){
  66. sh 'cico node done ${SSID}'
  67. }
  68. stage('Notify PR'){
  69. res = currentBuild.currentResult
  70. notifyPagurePR("pagure", "Build " + res + "! ", res, "FINALIZED")
  71. }
  72. stage('Archive Artifacts'){
  73. archiveArtifacts artifacts: 'pagure/results-py2/'
  74. archiveArtifacts artifacts: 'pagure/results-py3/'
  75. }
  76. }
  77. }