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
6 http://www.apache.org/licenses/LICENSE-2.0
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
12 See the License for the specific language governing permissions and
13 limitations under the License.
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
33 stage('LICENSE SCAN') {
34 agent { label 'osm1' }
36 echo "Clones Devops repo:"
38 git url: "${params.PROJECT_URL_PREFIX}/osm/devops", branch: "${params.GERRIT_BRANCH}"
41 sh "devops/tools/license_scan.sh"
44 stage('PRE-CHECKS AND UNIT TESTS') {
47 filename 'Dockerfile.testing'
51 stage('Linting tests') {
53 echo "Linting tests (flake8):"
54 sh "devops-stages/new-pipeline/stage-lint.sh"
59 echo "Unit tests (unittest):"
60 sh "devops-stages/new-pipeline/stage-test.sh"
66 echo "Saves all the results:"
67 // archiveArtifacts artifacts: 'relative/path/to/files/**/*.txt', fingerprint: true
71 stage('DOCKER IMAGE BUILD AND PUSH') {
72 agent { label 'osm2' }
74 stage('Build image') {
76 echo "Building ${params.IMAGENAME}:${env.BUILD_NUMBER} image:"
77 // Here we have to use Dockerfile.production
79 dockerImage = docker.build "${params.IMAGENAME}:${env.BUILD_NUMBER}"
83 stage('Upload to private registry') {
85 echo "Here it would upload the image with appropriate tags: build number, latest:"
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")
94 stage('Remove unused Docker image') {
96 echo "Here it will remove the docker image"
97 // sh "docker rmi ${params.IMAGENAME}:${env.BUILD_NUMBER}"
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"
108 stage('UNIT TESTS OVER RUNNING CONTAINER') {
111 image "${params.DOCKER_REGISTRY}/${params.IMAGENAME}:${env.BUILD_NUMBER}"
115 echo "The image has been successfully instantiated"
116 echo "(no additional unit tests over running container are required for this module)"
119 stage('INVOKE E2E SMOKE TESTS') {
120 agent { label 'system' }
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)
128 //build job: '<Job name>', parameters: [[$class: 'StringParameterValue', name: 'param1', value: 'test_param']]