Header Ads

Jenkins Master Template Continuos Deployment

 

 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
pipeline {
  triggers {
    pollSCM('* * * * *')
  }
  agent {
    kubernetes {
      defaultContainer 'MyBaseContainer'
      yaml """
spec: 
  containers:
  - name: MyBaseContainer
    image: MyRegistery/MyBaseContainer
    imagePullPolicy: Always
    command:
    - cat
    tty: true
  - name: docker
    image: docker
    command:
    - cat
    tty: true
    volumeMounts:
    - mountPath: /var/run/docker.sock
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      path: /var/run/docker.sock
"""
    }
  }
  options {
    disableConcurrentBuilds()
  }
  stages {
    stage('Building the docker image') {
      steps {
        container('docker') {
          checkout scm
          sh """
            docker build -t MyMicroServiceImageToBuild:${env.GIT_COMMIT} .
            docker version
          """
        }
      }
    }
    stage('Pushing the docker image when master') {
      when {
        branch 'master'
      }
      steps {
        container('docker') {
          sh """
            docker tag MyMicroServiceImageToBuild:${env.GIT_COMMIT} MyRegistery/MyBaseContainer
            docker push MyRegistery/MyBaseContainer
          """
        }
      }
    }
    stage('Installing required modules') {
      steps {
	      container('MyBaseContainer') {
	       sh """
	         pip install -r requirements.txt
	       """
	      }
      }
    }
    stage('Static Analysis') {
      parallel {
        stage('Pep 8 Modules') {
          steps {
            sh "python3 /usr/local/bin/pycodestyle --max-line-length=160 MyCodeFolder"
          }
        }
        stage('Pylint') {
          steps {
            sh "python3 /usr/local/bin/pylint --max-line-length=160  MyCodeFolder"
          }
        }
      }
    }
    stage('Unit Test') {
      parallel {
        stage('Backend') {
          steps {
            // Will add the unit tests later
            sh '''
              cd  MyUTCodeFolder
              run my UT's here
            '''
          }
        }
      }
    }
  }
}

No comments

Powered by Blogger.