Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c407ebd7c6142951d02caa72d4f8f3f883dd5360 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// When the parameters change, this should be increased so that the build does nothing other than update the parameters used for the next build.
def pipelineVersion = '1'

pipeline {
  agent { label 'migration' }

   options {
    buildDiscarder(logRotator(numToKeepStr: '10'))
    disableConcurrentBuilds()
    skipDefaultCheckout true
  }

  tools {
    maven 'apache-maven-latest'
    jdk 'oracle-jdk8-latest'
  }

  environment {
    JUSTJ_PUBLISH_LOCATION = 'sample-products'
    JUSTJ_BUILD_TIME_STAMP = sh(returnStdout: true, script: 'date +%Y%m%d%H%M').trim()
    JUSTJ_URL = 'https://download.eclipse.org/justj'
    JUSTJ_STORAGE_LOCATION = '/home/data/httpd/download.eclipse.org/justj'
  }

  parameters {
    string(
      name: 'PIPELINE_VERSION',
      defaultValue: "${pipelineVersion}",
      description: """${pretty(
        '''
        If the parameter definitions have changed, this version will be out-dated.
        The script will run but will do nothing other than updating the parameter definitions of the job as a side-effect.
        '''
      )}""")

    string(
      name: 'JRE_REPOSITORY',
      defaultValue: 'https://download.eclipse.org/justj/jres/17/updates/milestone/latest',
      description: """${pretty(
        '''
        Choose the URL of the JRE p2 repository to use.
        '''
      )}""")

    string(
      name: 'ECLIPSE_REPOSITORY',
      defaultValue: 'https://download.eclipse.org/releases/2021-09',
      description: """${pretty(
        '''
        Choose the URL of the release train repository to use.
        '''
      )}""")

    booleanParam(
      name: 'PROMOTE',
      defaultValue: false,
      description: """${pretty(
        '''
        Whether to promote the build to the download server.
        '''
      )}""")
  }

  stages {
    stage('Display Parameters') {
      steps {
        echo "JRE_REPOSITORY=${params.JRE_REPOSITORY}"
        echo "ECLIPSE_REPOSITORY=${params.ECLIPSE_REPOSITORY}"
        echo "PROMOTE=${params.PROMOTE}"
        echo "PIPELINE_VERSION=${params.PIPELINE_VERSION}"
        script {
          env.PROMOTE = params.PROMOTE
          env.ECLIPSE_REPOSITORY = params.ECLIPSE_REPOSITORY
          env.JRE_REPOSITORY = params.JRE_REPOSITORY
          env.PIPELINE_VERSION = params.PIPELINE_VERSION
        }
      }
    }

    stage('Git Checkout') {
      when {
        environment name: 'PIPELINE_VERSION', value: pipelineVersion
      }

      steps {
        script {
          def gitVariables = checkout(
            poll: false,
            scm: [
              $class: 'GitSCM',
              branches: [[name: '*/master']],
              doGenerateSubmoduleConfigurations: false,
              extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'justj.tools']],
              submoduleCfg: [],
              userRemoteConfigs: [[url: 'git://git.eclipse.org/gitroot/justj/justj.tools.git']]
            ]
          )

          echo "$gitVariables"
          env.GIT_COMMIT = gitVariables.GIT_COMMIT
        }
      }
    }

    stage('Build Sample Products') {
      when {
        environment name: 'PIPELINE_VERSION', value: pipelineVersion
      }

      steps {
        dir('justj.tools/products/org.eclipse.justj.tools.sample.product') {
          sh '''
            mvn  --no-transfer-progress -Dorg.eclipse.justj.eclipse.repository=$ECLIPSE_REPOSITORY -Dorg.eclipse.justj.jre.repository=$JRE_REPOSITORY -DPACK_AND_SIGN=true -Dorg.eclipse.justj.p2.manager.build.url=$JOB_URL -Dgit.commit=$GIT_COMMIT -Dbuild.id=$BUILD_NUMBER clean verify
            '''
        }
      }
    }

    stage('Promote Results') {
      when {
        environment name: 'PIPELINE_VERSION', value: pipelineVersion
        environment name: 'PROMOTE', value: 'true'
      }
      steps {
        dir('justj.tools/products/org.eclipse.justj.tools.sample.product/target/products') {
          sshagent(['projects-storage.eclipse.org-bot-ssh']) {
            sh '''
              ssh genie.justj@projects-storage.eclipse.org "
              rm -rf $JUSTJ_STORAGE_LOCATION/$JUSTJ_PUBLISH_LOCATION/*
              mkdir -p $JUSTJ_STORAGE_LOCATION/$JUSTJ_PUBLISH_LOCATION/$JUSTJ_BUILD_TIME_STAMP
              "
              scp *.zip *.tar.gz *.dmg genie.justj@projects-storage.eclipse.org:$JUSTJ_STORAGE_LOCATION/$JUSTJ_PUBLISH_LOCATION/$JUSTJ_BUILD_TIME_STAMP
            '''
          }
        }
      }
    }

    stage('Archive Results') {
      when {
        environment name: 'PIPELINE_VERSION', value: pipelineVersion
      }

      steps {
        dir('justj.tools/products/org.eclipse.justj.tools.sample.product/target/products') {
          archiveArtifacts '*.zip,*.tar.gz,*.dmg'
        }
      }
    }
  }

  post {
    failure {
      mail to: 'ed.merks@gmail.com',
      subject: "[JustJ CI] Build Failure ${currentBuild.fullDisplayName}",
      mimeType: 'text/html',
      body: "Project: ${env.JOB_NAME}<br/>Build Number: ${env.BUILD_NUMBER}<br/>Build URL: ${env.BUILD_URL}<br/>Console: ${env.BUILD_URL}/console"
    }

    fixed {
      mail to: 'ed.merks@gmail.com',
      subject: "[JustJ CI] Back to normal ${currentBuild.fullDisplayName}",
      mimeType: 'text/html',
      body: "Project: ${env.JOB_NAME}<br/>Build Number: ${env.BUILD_NUMBER}<br/>Build URL: ${env.BUILD_URL}<br/>Console: ${env.BUILD_URL}/console"
    }

    cleanup {
      deleteDir()
    }
  }
}

def pretty(string) {
  return string.replaceAll("^\r?\n", "").replaceAll("\r?\n\$", "").replace("\r", "").stripIndent()
}

Back to the top