blob: 0d8cddb782e3ba5940987ab09cee19c26d21e82e [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:"
garciadeblasb1bcbf92020-09-11 14:24:54 +000077 // Here we have to use Dockerfile.production
garciadeblas30b97562020-09-11 09:13:47 +000078 script {
79 dockerImage = docker.build "${params.IMAGENAME}:${env.BUILD_NUMBER}"
80 }
81 }
82 }
83 stage('Upload to private registry') {
84 steps{
85 echo "Here it would upload the image with appropriate tags: build number, latest:"
86 // script {
87 // docker.withRegistry( params.DOCKER_REGISTRY_PROTOCOL + params.DOCKER_REGISTRY, params.DOCKER_CREDENTIALS ) {
88 // dockerImage.push("${env.BUILD_NUMBER}")
89 // dockerImage.push("${params.GERRIT_BRANCH}-latest")
90 // }
91 // }
92 }
93 }
94 stage('Remove unused Docker image') {
95 steps{
96 echo "Here it will remove the docker image"
97 // sh "docker rmi ${params.IMAGENAME}:${env.BUILD_NUMBER}"
98
99 // // Name format for private registry
100 // sh "docker rmi ${params.DOCKER_REGISTRY}/${params.IMAGENAME}:${env.BUILD_NUMBER}"
101 // sh "docker rmi ${params.DOCKER_REGISTRY}/${params.IMAGENAME}:${params.GERRIT_BRANCH}-latest"
102 // // Name format for default public registry
103 // //sh "docker rmi ${IMAGENAME}:latest"
104 }
105 }
106 }
107 }
108 stage('UNIT TESTS OVER RUNNING CONTAINER') {
109 agent {
110 docker {
111 image "${params.DOCKER_REGISTRY}/${params.IMAGENAME}:${env.BUILD_NUMBER}"
112 }
113 }
114 steps {
115 echo "The image has been successfully instantiated"
116 echo "(no additional unit tests over running container are required for this module)"
117 }
118 }
119 stage('INVOKE E2E SMOKE TESTS') {
120 agent { label 'system' }
121 steps {
122 echo "Triggering E2E tests pipeline"
123 build job: 'E2E-install-and-testing'
124 // As last stage, here it should call the "Deployment and E2E Testing" pipeline with the appropriate parameters to:
125 // - Run smoke tests only
126 // - Avoid pushing images to public Docker Registry (this will be done once Daily)
127 //
128 //build job: '<Job name>', parameters: [[$class: 'StringParameterValue', name: 'param1', value: 'test_param']]
129 }
130 }
131 }
132}
133