Jenkinsfile 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // CI/CD for Gogs: push and pull requests targeting main.
  2. // Builds, tests and packaging run inside Docker (DinD), not on the Jenkins host.
  3. // Triggers are configured on the Jenkins job (Generic Webhook) + Gogs webhooks.
  4. pipeline {
  5. agent {
  6. docker {
  7. image 'ura-ci-maven:21'
  8. label 'built-in'
  9. alwaysPull false
  10. args '-u root -v jenkins-m2-cache:/root/.m2 -e MAVEN_OPTS=-Xmx1024m'
  11. }
  12. }
  13. options {
  14. timestamps()
  15. disableConcurrentBuilds()
  16. timeout(time: 45, unit: 'MINUTES')
  17. buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '10'))
  18. }
  19. stages {
  20. stage('Checkout') {
  21. steps {
  22. script {
  23. def sha = env.pr_head_sha ?: env.after ?: 'main'
  24. if (!sha?.trim() || sha == 'null' || sha == '0000000000000000000000000000000000000000') {
  25. sha = 'main'
  26. }
  27. echo "Gogs event ref=${env.ref} action=${env.action} pr=#${env.pr_number} sha=${sha}"
  28. checkout([
  29. $class: 'GitSCM',
  30. branches: [[name: sha]],
  31. extensions: [[$class: 'CloneOption', shallow: false, noTags: false]],
  32. userRemoteConfigs: [[url: 'https://git.barcelos.dev/allan/jenkins-mfa-auth-plugin.git']]
  33. ])
  34. }
  35. }
  36. }
  37. stage('Test') {
  38. steps {
  39. sh 'mvn -B -ntp verify'
  40. }
  41. post {
  42. always {
  43. junit allowEmptyResults: true, testResults: 'target/surefire-reports/*.xml'
  44. }
  45. }
  46. }
  47. stage('Package') {
  48. steps {
  49. sh 'mvn -B -ntp -DskipTests -Dset.changelist package'
  50. sh 'ls -la target/*.hpi target/*.jar'
  51. archiveArtifacts artifacts: 'target/*.hpi,target/*-SNAPSHOT.jar', fingerprint: true
  52. }
  53. }
  54. stage('Release') {
  55. when {
  56. allOf {
  57. expression { env.ref == 'refs/heads/main' }
  58. expression { !env.pr_number?.trim() || env.pr_number == 'null' }
  59. }
  60. }
  61. steps {
  62. echo 'Release artifact is the archived HPI from this build (lastSuccessfulBuild).'
  63. sh '''
  64. set -e
  65. HPI=$(ls -1 target/*.hpi | head -1)
  66. echo "HPI=${HPI} size=$(wc -c < "$HPI") sha256=$(sha256sum "$HPI" | awk '{print $1}')"
  67. '''
  68. }
  69. }
  70. }
  71. post {
  72. always {
  73. sh 'chmod -R a+rwX "$WORKSPACE" || true'
  74. }
  75. }
  76. }