.cico.pipeline 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_TRACE=1 GIT_CURL_VERBOSE=1 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_containers.sh'
  55. }
  56. }
  57. } catch (e) {
  58. currentBuild.result = "FAILURE"
  59. throw e
  60. } finally {
  61. stage('Sync Artifacts'){
  62. syncfromduffynode('pagure/results_f31-rpms-py3/')
  63. syncfromduffynode('pagure/results_centos7-rpms-py2/')
  64. syncfromduffynode('pagure/results_fedora-pip-py3/')
  65. }
  66. stage('Deallocate Node'){
  67. sh 'cico node done ${SSID}'
  68. }
  69. stage('Notify PR'){
  70. res = currentBuild.currentResult
  71. notifyPagurePR("pagure", "Build " + res + "! ", res, "FINALIZED")
  72. }
  73. stage('Archive Artifacts'){
  74. archiveArtifacts artifacts: 'pagure/results_f31-rpms-py3/'
  75. archiveArtifacts artifacts: 'pagure/results_centos7-rpms-py2/'
  76. archiveArtifacts artifacts: 'pagure/results_fedora-pip-py3/'
  77. }
  78. }
  79. }