/* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ pipeline { agent none parameters { string(defaultValue: env.BRANCH_NAME, description: '', name: 'GERRIT_BRANCH') string(defaultValue: 'osm/NBI', description: '', name: 'GERRIT_PROJECT') string(defaultValue: env.GERRIT_REFSPEC, description: '', name: 'GERRIT_REFSPEC') string(defaultValue: env.GERRIT_PATCHSET_REVISION, description: '', name: 'GERRIT_PATCHSET_REVISION') string(defaultValue: 'https://osm.etsi.org/gerrit', description: '', name: 'PROJECT_URL_PREFIX') booleanParam(defaultValue: false, description: '', name: 'TEST_INSTALL') // string(defaultValue: 'artifactory-osm', description: '', name: 'ARTIFACTORY_SERVER') // New parameters for Docker image build string(defaultValue: 'opensourcemano/nbi', description: 'Docker Image Name', name: 'IMAGENAME') string(defaultValue: 'localhost:5000', description: 'Docker Registry', name: 'DOCKER_REGISTRY') string(defaultValue: 'http://', description: 'Docker Registry protocol', name: 'DOCKER_REGISTRY_PROTOCOL') string(defaultValue: '', description: 'ID of Docker Registry Credentials', name: 'DOCKER_CREDENTIALS') // `defaultValue` to be updated with actual ID in Jenkins whenever needed } stages { stage('LICENSE SCAN') { agent { label 'osm1' } steps { echo "Clones Devops repo:" dir('devops') { git url: "${params.PROJECT_URL_PREFIX}/osm/devops", branch: "${params.GERRIT_BRANCH}" } echo "License scan:" sh "devops/tools/license_scan.sh" } } stage('PRE-CHECKS AND UNIT TESTS') { agent { dockerfile { filename 'Dockerfile.testing' } } stages { stage('Linting tests') { steps { echo "Linting tests (flake8):" sh "devops-stages/new-pipeline/stage-lint.sh" } } stage('Unit tests') { steps { echo "Unit tests (unittest):" sh "devops-stages/new-pipeline/stage-test.sh" } } } post { always { echo "Saves all the results:" // archiveArtifacts artifacts: 'relative/path/to/files/**/*.txt', fingerprint: true } } } stage('DOCKER IMAGE BUILD AND PUSH') { agent { label 'osm2' } stages { stage('Build image') { steps{ echo "Building ${params.IMAGENAME}:${env.BUILD_NUMBER} image:" script { dockerImage = docker.build "${params.IMAGENAME}:${env.BUILD_NUMBER}" } } } stage('Upload to private registry') { steps{ echo "Here it would upload the image with appropriate tags: build number, latest:" // script { // docker.withRegistry( params.DOCKER_REGISTRY_PROTOCOL + params.DOCKER_REGISTRY, params.DOCKER_CREDENTIALS ) { // dockerImage.push("${env.BUILD_NUMBER}") // dockerImage.push("${params.GERRIT_BRANCH}-latest") // } // } } } stage('Remove unused Docker image') { steps{ echo "Here it will remove the docker image" // sh "docker rmi ${params.IMAGENAME}:${env.BUILD_NUMBER}" // // Name format for private registry // sh "docker rmi ${params.DOCKER_REGISTRY}/${params.IMAGENAME}:${env.BUILD_NUMBER}" // sh "docker rmi ${params.DOCKER_REGISTRY}/${params.IMAGENAME}:${params.GERRIT_BRANCH}-latest" // // Name format for default public registry // //sh "docker rmi ${IMAGENAME}:latest" } } } } stage('UNIT TESTS OVER RUNNING CONTAINER') { agent { docker { image "${params.DOCKER_REGISTRY}/${params.IMAGENAME}:${env.BUILD_NUMBER}" } } steps { echo "The image has been successfully instantiated" echo "(no additional unit tests over running container are required for this module)" } } stage('INVOKE E2E SMOKE TESTS') { agent { label 'system' } steps { echo "Triggering E2E tests pipeline" build job: 'E2E-install-and-testing' // As last stage, here it should call the "Deployment and E2E Testing" pipeline with the appropriate parameters to: // - Run smoke tests only // - Avoid pushing images to public Docker Registry (this will be done once Daily) // //build job: '', parameters: [[$class: 'StringParameterValue', name: 'param1', value: 'test_param']] } } } }