-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdemo.jenkinsfile
More file actions
109 lines (98 loc) · 2.63 KB
/
demo.jenkinsfile
File metadata and controls
109 lines (98 loc) · 2.63 KB
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
pipeline {
agent any
parameters {
string(name: 'SLACK_CHANNEL', defaultValue: '#deploys', description: '')
choice(name: 'TYPE', choices: 'aut\ncron\ndata', description: 'Autoscaling, Cron or Data')
booleanParam(name: 'DEPLOY', defaultValue: false, description: 'Update aws ami')
}
options {
ansiColor("xterm")
timestamps()
timeout(time: 15, unit: "MINUTES")
}
environment {
ARTIFACT = "${env.BUILD_NUMBER}.zip"
SLACK_MESSAGE = "Job '${env.JOB_NAME}' Build ${env.BUILD_NUMBER} URL ${env.BUILD_URL}"
}
stages {
stage("Repository") {
steps {
checkout scm
}
}
stage('Run') {
steps {
echo "hello from $USER"
sh "id"
echo "PATH $PATH"
echo "workspace ${env.WORKSPACE}"
sh "mkdir -p demo/src/"
sh "touch demo.txt"
sh "wget https://github.com/Kitware/CMake/releases/download/v3.15.0-rc2/cmake-3.15.0-rc2.tar.gz"
sh "ls -la"
echo "job_name ${env.JOB_NAME}"
echo "build_number ${env.BUILD_NUMBER}"
echo "artifact: ${env.ARTIFACT}"
echo "message: ${env.SLACK_MESSAGE}"
echo "canal ${params.SLACK_CHANNEL}"
echo "tipo ${params.TYPE}"
echo "launch ${params.LAUNCH_CONFIGURATION}"
}
}
stage('Inspection') {
steps {
parallel (
syntax: { echo "check syntax" },
grep: { sh "echo buscando_var_dump" }
)
}
}
stage ('Build') {
steps {
script {
def ID = sh(returnStdout: true, script: "./ami_id.sh ${env.BUILD_NUMBER}").trim()
sh "./build_ami.sh ${ID}"
}
sh "zip -r ${env.ARTIFACT} 4-fake-delegation/"
}
}
stage ("Ask") {
input {
message "Are you sure?"
ok "Yes"
}
steps {
sh "echo ok_seguimos"
}
}
stage ('Deploy') {
when {
expression {
return params.DEPLOY ==~ /(?i)(Y|YES|T|TRUE|ON|RUN)/
}
}
steps {
sh "echo hare_deploy"
build job: "mydemo", parameters: [
[$class: 'StringParameterValue', name: "SLACK", value: '#deploys']
]
}
}
}
post {
always {
archiveArtifacts artifacts: "${env.ARTIFACT}", onlyIfSuccessful: true
sh "rm -f ${ARTIFACT}"
echo "Job has finished"
}
success {
slackSendMessage "good"
}
failure {
slackSendMessage "danger"
}
}
}
def slackSendMessage(String color){
slackSend channel: "${params.SLACK_CHANNEL}", color: color, failOnError: true, message: "$SLACK_MESSAGE"
}