Jenkinsfile 3.7 KB
Newer Older
1
2
3
4
5
@Library('common-shared') _

pipeline {
  agent {
    kubernetes {
Mikaël Barbero's avatar
Mikaël Barbero committed
6
      label 'kubedeploy-agent'
7
      yaml '''
Mikaël Barbero's avatar
Mikaël Barbero committed
8
9
10
11
12
        apiVersion: v1
        kind: Pod
        spec:
          containers:
          - name: kubectl
13
            image: eclipsefdn/kubectl:okd-c1-1.24.2
Mikaël Barbero's avatar
Mikaël Barbero committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
            command:
            - cat
            tty: true
            resources:
              limits:
                cpu: 1
                memory: 1Gi
            volumeMounts:
            - mountPath: "/home/default/.kube"
              name: "dot-kube"
              readOnly: false
          - name: jnlp
            resources:
              limits:
                cpu: 1
                memory: 1Gi
          volumes:
          - name: "dot-kube"
            emptyDir: {}
33
34
35
36
37
38
39
40
      '''
    }
  }

  environment {
    NAMESPACE = 'foundation-internal-webdev-apps'
    IMAGE_NAME = 'eclipsefdn/eclipsefdn-github-sync'
    CONTAINER_NAME = 'eclipsefdn-github-sync'
41
42
    GL_IMAGE_NAME = 'eclipsefdn/eclipsefdn-gitlab-sync'
    GL_CONTAINER_NAME = 'eclipsefdn-gitlab-sync'
43
44
    BUI_IMAGE_NAME = 'eclipsefdn/eclipsefdn-import-backup'
    BUI_CONTAINER_NAME = 'eclipsefdn-import-backup'
45
46
47
48
49
50
51
52
53
54
55
    TAG_NAME = sh(
      script: """
        GIT_COMMIT_SHORT=\$(git rev-parse --short ${env.GIT_COMMIT})
        printf \${GIT_COMMIT_SHORT}-${env.BUILD_NUMBER}
      """,
      returnStdout: true
    )
  }

  options {
    buildDiscarder(logRotator(numToKeepStr: '10'))
56
    timeout(time: 30, unit: 'MINUTES') 
57
58
  }

Mikaël Barbero's avatar
Mikaël Barbero committed
59
  triggers {
60
    // build once a week to keep up with parents images updates
Mikaël Barbero's avatar
Mikaël Barbero committed
61
    cron('H H * * H')
62
63
64
65
66
67
68
69
70
71
  }

  stages {
    stage('Build docker image') {
      agent {
        label 'docker-build'
      }
      steps {
        sh '''
          docker build --pull -t ${IMAGE_NAME}:${TAG_NAME} -t ${IMAGE_NAME}:latest .
72
          docker build --pull -t ${GL_IMAGE_NAME}:${TAG_NAME} -t ${GL_IMAGE_NAME}:latest -f Dockerfile.gitlab .
73
          docker build --pull -t ${BUI_IMAGE_NAME}:${TAG_NAME} -t ${BUI_IMAGE_NAME}:latest -f Dockerfile.import .
74
75
76
77
78
        '''
      }
    }

    stage('Push docker image') {
79
      when {
80
        branch 'production'
81
      }
82
83
84
85
86
87
88
89
      agent {
        label 'docker-build'
      }
      steps {
        withDockerRegistry([credentialsId: '04264967-fea0-40c2-bf60-09af5aeba60f', url: 'https://index.docker.io/v1/']) {
          sh '''
            docker push ${IMAGE_NAME}:${TAG_NAME}
            docker push ${IMAGE_NAME}:latest
90
91
            docker push ${GL_IMAGE_NAME}:${TAG_NAME}
            docker push ${GL_IMAGE_NAME}:latest
92
93
            docker push ${BUI_IMAGE_NAME}:${TAG_NAME}
            docker push ${BUI_IMAGE_NAME}:latest
94
95
96
97
98
99
100
          '''
        }
      }
    }

    stage('Deploy to cluster') {
      when {
101
        branch 'production'
102
103
104
      }
      steps {
        container('kubectl') {
Mikaël Barbero's avatar
Mikaël Barbero committed
105
106
107
          updateContainerImage([
            namespace: "${env.NAMESPACE}",
            selector: "job=github-sync",
108
            kind: "cronjob.v1.batch",
Mikaël Barbero's avatar
Mikaël Barbero committed
109
110
111
112
113
114
            containerName: "${env.CONTAINER_NAME}",
            newImageRef: "${env.IMAGE_NAME}:${env.TAG_NAME}"
          ])
          updateContainerImage([
            namespace: "${env.NAMESPACE}",
            selector: "job=gitlab-sync",
115
            kind: "cronjob.v1.batch",
Mikaël Barbero's avatar
Mikaël Barbero committed
116
117
118
119
120
121
            containerName: "${env.GL_CRONJOB_NAME}",
            newImageRef: "${env.GL_IMAGE_NAME}:${env.TAG_NAME}"
          ])
          updateContainerImage([
            namespace: "${env.NAMESPACE}",
            selector: "job=github-org-backup",
122
            kind: "cronjob.v1.batch",
Mikaël Barbero's avatar
Mikaël Barbero committed
123
124
125
            containerName: "${env.BUI_CONTAINER_NAME}",
            newImageRef: "${env.BUI_IMAGE_NAME}:${env.TAG_NAME}"
          ])
126
127
128
129
130
131
132
133
134
135
136
137
        }
      }
    }
  }

  post {
    always {
      deleteDir() /* clean up workspace */
      sendNotifications currentBuild
    }
  }
}