blob: d9b53dd62c108e368f98294371157a9ce7863051 [file] [log] [blame]
garciadeblas30b97562020-09-11 09:13:47 +00001/*
2 Licensed under the Apache License, Version 2.0 (the "License");
3 you may not use this file except in compliance with the License.
4 You may obtain a copy of the License at
5
6 http://www.apache.org/licenses/LICENSE-2.0
7
8 Unless required by applicable law or agreed to in writing, software
9 distributed under the License is distributed on an "AS IS" BASIS,
10 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11 implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14*/
15
16pipeline {
17 agent none
18 parameters {
19 string(defaultValue: env.BRANCH_NAME, description: '', name: 'GERRIT_BRANCH')
20 string(defaultValue: 'osm/NBI', description: '', name: 'GERRIT_PROJECT')
21 string(defaultValue: env.GERRIT_REFSPEC, description: '', name: 'GERRIT_REFSPEC')
22 string(defaultValue: env.GERRIT_PATCHSET_REVISION, description: '', name: 'GERRIT_PATCHSET_REVISION')
23 string(defaultValue: 'https://osm.etsi.org/gerrit', description: '', name: 'PROJECT_URL_PREFIX')
24 booleanParam(defaultValue: false, description: '', name: 'TEST_INSTALL')
25 // string(defaultValue: 'artifactory-osm', description: '', name: 'ARTIFACTORY_SERVER')
26 // New parameters for Docker image build
27 string(defaultValue: 'opensourcemano/nbi', description: 'Docker Image Name', name: 'IMAGENAME')
28 string(defaultValue: 'localhost:5000', description: 'Docker Registry', name: 'DOCKER_REGISTRY')
29 string(defaultValue: 'http://', description: 'Docker Registry protocol', name: 'DOCKER_REGISTRY_PROTOCOL')
30 string(defaultValue: '', description: 'ID of Docker Registry Credentials', name: 'DOCKER_CREDENTIALS') // `defaultValue` to be updated with actual ID in Jenkins whenever needed
31 }
32 stages {
33 stage('LICENSE SCAN') {
34 agent { label 'osm1' }
35 steps {
36 echo "Clones Devops repo:"
37 dir('devops') {
38 git url: "${params.PROJECT_URL_PREFIX}/osm/devops", branch: "${params.GERRIT_BRANCH}"
39 }
40 echo "License scan:"
41 sh "devops/tools/license_scan.sh"
42 }
43 }
44 stage('PRE-CHECKS AND UNIT TESTS') {
45 agent {
46 dockerfile {
47 filename 'Dockerfile.testing'
48 }
49 }
50 stages {
51 stage('Linting tests') {
52 steps {
53 echo "Linting tests (flake8):"
54 sh "devops-stages/new-pipeline/stage-lint.sh"
55 }
56 }
57 stage('Unit tests') {
58 steps {
59 echo "Unit tests (unittest):"
60 sh "devops-stages/new-pipeline/stage-test.sh"
61 }
62 }
63 }
64 post {
65 always {
66 echo "Saves all the results:"
67 // archiveArtifacts artifacts: 'relative/path/to/files/**/*.txt', fingerprint: true
68 }
69 }
70 }
71 stage('DOCKER IMAGE BUILD AND PUSH') {
72 agent { label 'osm2' }
73 stages {
74 stage('Build image') {
75 steps{
76 echo "Building ${params.IMAGENAME}:${env.BUILD_NUMBER} image:"
77 script {
78 dockerImage = docker.build "${params.IMAGENAME}:${env.BUILD_NUMBER}"
79 }
80 }
81 }
82 stage('Upload to private registry') {
83 steps{
84 echo "Here it would upload the image with appropriate tags: build number, latest:"
85 // script {
86 // docker.withRegistry( params.DOCKER_REGISTRY_PROTOCOL + params.DOCKER_REGISTRY, params.DOCKER_CREDENTIALS ) {
87 // dockerImage.push("${env.BUILD_NUMBER}")
88 // dockerImage.push("${params.GERRIT_BRANCH}-latest")
89 // }
90 // }
91 }
92 }
93 stage('Remove unused Docker image') {
94 steps{
95 echo "Here it will remove the docker image"
96 // sh "docker rmi ${params.IMAGENAME}:${env.BUILD_NUMBER}"
97
98 // // Name format for private registry
99 // sh "docker rmi ${params.DOCKER_REGISTRY}/${params.IMAGENAME}:${env.BUILD_NUMBER}"
100 // sh "docker rmi ${params.DOCKER_REGISTRY}/${params.IMAGENAME}:${params.GERRIT_BRANCH}-latest"
101 // // Name format for default public registry
102 // //sh "docker rmi ${IMAGENAME}:latest"
103 }
104 }
105 }
106 }
107 stage('UNIT TESTS OVER RUNNING CONTAINER') {
108 agent {
109 docker {
110 image "${params.DOCKER_REGISTRY}/${params.IMAGENAME}:${env.BUILD_NUMBER}"
111 }
112 }
113 steps {
114 echo "The image has been successfully instantiated"
115 echo "(no additional unit tests over running container are required for this module)"
116 }
117 }
118 stage('INVOKE E2E SMOKE TESTS') {
119 agent { label 'system' }
120 steps {
121 echo "Triggering E2E tests pipeline"
122 build job: 'E2E-install-and-testing'
123 // As last stage, here it should call the "Deployment and E2E Testing" pipeline with the appropriate parameters to:
124 // - Run smoke tests only
125 // - Avoid pushing images to public Docker Registry (this will be done once Daily)
126 //
127 //build job: '<Job name>', parameters: [[$class: 'StringParameterValue', name: 'param1', value: 'test_param']]
128 }
129 }
130 }
131}
132