forked from zeromq/zproject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile-deploy.example
More file actions
107 lines (103 loc) · 4.67 KB
/
Jenkinsfile-deploy.example
File metadata and controls
107 lines (103 loc) · 4.67 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
/* The following example Jenkinsfile is a skeleton to copy into your CI
* scripts repository and configure a MultiBranch Pipeline job from it.
* This would create a job instance from every branch that contains this
* file, so you can adapt the content to your installation's tools and
* call this job to deploy projects generated with zproject.
*
* Then in your Jenkins Management Web-GUI go to Configure System /
* / Global properties / Environment variables and Add a new variable
* DEFAULT_DEPLOY_JOB_NAME with value like '/my-deploy/master', and a
* DEFAULT_DEPLOY_BRANCH_PATTERN like '^(master|feature/,*|release/.*)$'
*
* Contributed to zproject, Copyright (C) 2017 by Eaton
* Author: Jim Klimov <EvgenyKlimov@eaton.com>
*/
pipeline {
// Select an agent with proper tools and access needed for deployment
agent { label "deploy-tools" }
parameters {
string (
defaultValue: '',
description: 'Git repo URL with sources',
name: 'DEPLOY_GIT_URL')
string (
defaultValue: '',
description: 'The branch which passed tests (e.g. "master") - influences which OBS project to push into',
name: 'DEPLOY_GIT_BRANCH')
string (
defaultValue: '',
description: 'The commit ID of the sources to check out (may be not current HEAD of that repo/branch)',
name: 'DEPLOY_GIT_COMMIT')
string (
defaultValue: 'https://github.com/myorg/myjenkinsscripts.git',
description: 'GIT Repo with CI scripts and tools',
name: 'CI_REPO_FORK')
string (
defaultValue: 'origin/master',
description: '',
name: 'CI_REPO_BRANCH')
string (
defaultValue: '',
description: '',
name: 'CI_REPO_REFSPEC')
// You may have more parameters passed here, to pass them down to your
// deployment script; make sure to set some sane defaults or guess blank
// values in your scripts
}
stages {
stage ('Sanity check') {
steps {
script {
if ( "${params["CI_REPO_BRANCH"]}" == "" || "${params["CI_REPO_FORK"]}" == "" ||
"${params["DEPLOY_GIT_URL"]}" == "" || "${params["DEPLOY_GIT_BRANCH"]}" == ""
) { return false; }
}
}
}
stage ('Checkout') {
parallel {
stage ('Checkout SRC') {
steps {
checkout([$class: 'GitSCM',
branches: [[name: "${params["DEPLOY_GIT_BRANCH"]}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'WipeWorkspace'],
[$class: 'RelativeTargetDirectory', relativeTargetDir: 'project'],
[$class: 'CloneOption', noTags: false, shallow: false]],
submoduleCfg: [],
userRemoteConfigs: [[url: "${params["DEPLOY_GIT_URL"]}", refspec: "${params["DEPLOY_GIT_COMMIT"]}"]]
// Maybe also pass a credentialsId with account who may read your repos, if access is restricted
])
}
}
stage ('Checkout CI scripts') {
steps {
checkout([$class: 'GitSCM',
branches: [[name: "${params["CI_REPO_BRANCH"]}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'WipeWorkspace'],
[$class: 'RelativeTargetDirectory', relativeTargetDir: 'ci'],
[$class: 'CloneOption', depth: 3, noTags: true, shallow: true, reference: "${env.WORKSPACE}/.git"]],
// Optimization above assumes that this Jenkinsfile-deploy lives in the same repo, so we know it is already checked out
submoduleCfg: [],
userRemoteConfigs: [[url: "${params["CI_REPO_FORK"]}", refspec: "${params["CI_REPO_REFSPEC"]}"]]
])
}
}
}
}
// Certainly, customize the code below to match your tools and their params
stage ('Deploy') {
steps {
sh """
DEPLOY_GIT_URL="${params["DEPLOY_GIT_URL"]}"
DEPLOY_GIT_BRANCH="${params["DEPLOY_GIT_BRANCH"]}"
DEPLOY_GIT_COMMIT="${params["DEPLOY_GIT_COMMIT"]}"
export DEPLOY_GIT_URL DEPLOY_GIT_BRANCH DEPLOY_GIT_COMMIT
cd project && \
../ci/update-deployment.sh
"""
}
}
}
}