-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
155 lines (135 loc) · 4.88 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env groovy
void changeBuildInfo(Map mapArgs) {
// Argument check first.
if (null == mapArgs) {
throw new Exception("Null mapArgs")
}
if (!mapArgs.containsKey("currentBuild")) {
throw new Exception("Missing currentBuild. args: " + mapArgs)
}
if (!mapArgs.containsKey("scmVersion")) {
throw new Exception("Missing scmVersion. args: " + mapArgs)
}
// Using default args.
def defaultMapArgs = [:]
Map mergedMap = defaultMapArgs << mapArgs
// Change the build display.
changeBuildDisplay(mergedMap)
}
void changeBuildDisplay(Map mapArgs) {
def currentBuild = mapArgs.currentBuild
def scmVersion = mapArgs.scmVersion
def user = null
if (mapArgs.containsKey("specificParams")) {
def specificParams = mapArgs.specificParams
if (null != specificParams) {
if (specificParams.containsKey("displayUser")) {
user = specificParams.displayUser
}
}
}
if (null == user) {
wrap([$class: 'BuildUser']) {
// Shows the user id.
if (null != env.BUILD_USER_ID) {
user = "${env.BUILD_USER_ID}"
} else {
// Most likely a scheduled trigger.
user = "JenkinsScheduler"
}
}
}
currentBuild.displayName += "-" + user
currentBuild.displayName += "-${scmVersion}"
}
// Args.
String scmUrl = env.scm_ur
// Same pipeline as before, but with job parameters.
pipeline {
agent any
options {
// See https://jenkins.io/doc/book/pipeline/syntax/#options .
skipStagesAfterUnstable()
// Avoid the 'Declarative: Checkout SCM' stage.
skipDefaultCheckout true
// Persist artifacts and console output for the specific number of recent Pipeline runs.
// daysToKeepStr: if not empty, build records are only kept up to this number of days
// numToKeepStr: if not empty, only up to this number of build records are kept
// artifactDaysToKeepStr: if not empty, artifacts from builds older than this number of days will be deleted, but the logs, history, reports, etc for the build will be kept
// artifactNumToKeepStr: if not empty, only up to this number of builds have their artifacts retained
buildDiscarder(logRotator(artifactDaysToKeepStr: '3', artifactNumToKeepStr: '', daysToKeepStr: '30', numToKeepStr: '60'))
}
// See https://jenkins.io/doc/book/pipeline/syntax/#parameters
parameters {
gitParameter(
branch: '',
branchFilter: 'origin/(.*)',
defaultValue: 'main',
description: 'Reference, which is a branch or a tag.',
name: 'GIT_REF',
quickFilterEnabled: true,
selectedValue: 'DEFAULT',
sortMode: 'DESCENDING_SMART',
tagFilter: '*',
type: 'PT_BRANCH_TAG',
)
}
stages {
stage('Init') {
steps {
// Clean up workspace.
deleteDir()
// Show environment information.
sh """
printenv
ls -al
echo -n "pwd: "
pwd
"""
}
}
stage('Scm on agent') {
steps {
script {
checkout scm
jobParams = params
// Change build information (display, description, etc.).
changeBuildInfo(
currentBuild: currentBuild,
scmVersion: jobParams.GIT_REF,
)
}
}
}
stage ('Build') {
steps {
script {
dir("container_docker") {
dockerImage = docker.build("${registryPrefix}cnes-lisa-globalfit1-idasoft:dev")
}
}
}
}
stage ('Deploy') {
steps {
script {
String credentialsId = "lisa_dockerhub"
String url= ""
docker.withRegistry(url, credentialsId) {
dockerImage.push()
}
}
}
}
}
post {
success {
script {
sh """
id
pwd
"""
}
}
}
}