.cico.pipeline 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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('Deallocate Node'){
  62. sh 'cico node done ${SSID}'
  63. }
  64. stage('Notify PR'){
  65. res = currentBuild.currentResult
  66. notifyPagurePR("pagure", "Build " + res + "! ", res, "FINALIZED")
  67. }
  68. }
  69. }