|
1 | | -#!/usr/bin/groovy |
| 1 | +@Library(['github.com/indigo-dc/jenkins-pipeline-library@release/2.1.1']) _ |
2 | 2 |
|
3 | | -@Library(['github.com/indigo-dc/jenkins-pipeline-library@release/1.4.0']) _ |
4 | | - |
5 | | -def job_result_url = '' |
| 3 | +def projectConfig |
6 | 4 |
|
7 | 5 | pipeline { |
8 | | - agent { |
9 | | - label 'python3.6' |
10 | | - } |
11 | | - |
12 | | - environment { |
13 | | - author_name = "Ignacio Heredia (CSIC)" |
14 | | - author_email = "iheredia@ifca.unican.es" |
15 | | - app_name = "image-classification-tf-dicom" |
16 | | - job_location = "Pipeline-as-code/DEEP-OC-org/DEEP-OC-image-classification-tf-dicom/${env.BRANCH_NAME}" |
17 | | - } |
| 6 | + agent any |
18 | 7 |
|
19 | 8 | stages { |
20 | | - stage('Code fetching') { |
21 | | - steps { |
22 | | - checkout scm |
23 | | - } |
24 | | - } |
25 | | - |
26 | | - stage('Style analysis') { |
| 9 | + stage('Application testing') { |
27 | 10 | steps { |
28 | | - ToxEnvRun('pep8') |
29 | | - } |
30 | | - post { |
31 | | - always { |
32 | | - WarningsReport('Pep8') |
33 | | - } |
34 | | - } |
35 | | - } |
36 | | - |
37 | | - stage('Security scanner') { |
38 | | - steps { |
39 | | - ToxEnvRun('bandit-report') |
40 | 11 | script { |
41 | | - if (currentBuild.result == 'FAILURE') { |
42 | | - currentBuild.result = 'UNSTABLE' |
43 | | - } |
44 | | - } |
45 | | - } |
46 | | - post { |
47 | | - always { |
48 | | - HTMLReport("/tmp/bandit", 'index.html', 'Bandit report') |
49 | | - } |
50 | | - } |
51 | | - } |
52 | | - |
53 | | - stage("Re-build Docker image") { |
54 | | - when { |
55 | | - anyOf { |
56 | | - branch 'master' |
57 | | - branch 'test' |
58 | | - buildingTag() |
59 | | - } |
60 | | - } |
61 | | - steps { |
62 | | - script { |
63 | | - def job_result = JenkinsBuildJob("${env.job_location}") |
64 | | - job_result_url = job_result.absoluteUrl |
| 12 | + projectConfig = pipelineConfig() |
| 13 | + buildStages(projectConfig) |
65 | 14 | } |
66 | 15 | } |
67 | 16 | } |
68 | 17 | } |
69 | | - |
70 | 18 | post { |
71 | | - failure { |
| 19 | + // publish results and clean-up |
| 20 | + always { |
72 | 21 | script { |
73 | | - currentBuild.result = 'FAILURE' |
74 | | - } |
75 | | - } |
76 | | - |
77 | | - always { |
78 | | - script { //stage("Email notification") |
79 | | - def build_status = currentBuild.result |
80 | | - build_status = build_status ?: 'SUCCESS' |
81 | | - def subject = """ |
82 | | -New ${app_name} build in Jenkins@DEEP:\ |
83 | | -${build_status}: Job '${env.JOB_NAME}\ |
84 | | -[${env.BUILD_NUMBER}]'""" |
85 | | - |
86 | | - def body = """ |
87 | | -Dear ${author_name},\n\n |
88 | | -A new build of '${app_name} DEEP application is available in Jenkins at:\n\n |
89 | | -* ${env.BUILD_URL}\n\n |
90 | | -terminated with '${build_status}' status.\n\n |
91 | | -Check console output at:\n\n |
92 | | -* ${env.BUILD_URL}/console\n\n |
93 | | -and resultant Docker image rebuilding job at (may be empty in case of FAILURE):\n\n |
94 | | -* ${job_result_url}\n\n |
95 | | -DEEP Jenkins CI service""" |
96 | | - |
97 | | - EmailSend(subject, body, "${author_email}") |
| 22 | + if (fileExists("flake8.log")) { |
| 23 | + // file locations are defined in tox.ini |
| 24 | + // publish results of the style analysis |
| 25 | + recordIssues(tools: [flake8(pattern: 'flake8.log', |
| 26 | + name: 'PEP8 report', |
| 27 | + id: "flake8_pylint")]) |
| 28 | + } |
| 29 | + if (fileExists("htmlcov/index.html")) { |
| 30 | + // publish results of the coverage test |
| 31 | + publishHTML([allowMissing: false, |
| 32 | + alwaysLinkToLastBuild: false, |
| 33 | + keepAll: true, |
| 34 | + reportDir: "htmlcov", |
| 35 | + reportFiles: 'index.html', |
| 36 | + reportName: 'Coverage report', |
| 37 | + reportTitles: '']) |
| 38 | + } |
| 39 | + if (fileExists("bandit/index.html")) { |
| 40 | + // publish results of the security check |
| 41 | + publishHTML([allowMissing: false, |
| 42 | + alwaysLinkToLastBuild: false, |
| 43 | + keepAll: true, |
| 44 | + reportDir: "bandit", |
| 45 | + reportFiles: 'index.html', |
| 46 | + reportName: 'Bandit report', |
| 47 | + reportTitles: '']) |
| 48 | + } |
98 | 49 | } |
| 50 | + // Clean after build |
| 51 | + cleanWs() |
99 | 52 | } |
100 | 53 | } |
101 | 54 | } |
0 commit comments