forked from jenkins-infra/jenkins.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile_k8s
126 lines (118 loc) · 3.51 KB
/
Jenkinsfile_k8s
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
def recordDeployment(owner, repo, ref, status, environmentURL, environment = "preview", description = "Deploy to preview environment") {
withCredentials([usernamePassword(credentialsId: 'github-app-infra', usernameVariable: 'GITHUB_APP', passwordVariable: 'GH_TOKEN')]) {
def json = writeJSON(returnText: true, json: [
"ref": ref,
"environment": environment,
"description": description,
"required_contexts": [],
"auto_merge": false,
"auto_inactive": false,
"transient_environment": environment != "production",
])
def id = readJSON(text: sh(script: "gh api repos/${owner}/${repo}/deployments -X POST --input - << EOF\n${json}\nEOF", returnStdout: true).trim()).id
if (id == ''){
error('Unable to create deployment')
}
json = writeJSON(returnText: true, json: [
"state": status,
"environment": environment,
"description": description,
"log_url": "${BUILD_URL}console",
"environment_url": environmentURL,
])
sh("gh api repos/${owner}/${repo}/deployments/${id}/statuses -X POST --input - << EOF\n${json}\nEOF")
}
}
pipeline {
agent {
kubernetes {
yaml '''
apiVersion: "v1"
kind: "Pod"
metadata:
labels:
jenkins: "agent"
job: "jenkins-io"
spec:
tolerations:
- key: "os"
operator: "Equal"
value: "linux"
effect: "NoSchedule"
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
restartPolicy: "Never"
automountServiceAccountToken: false
containers:
- name: "jnlp"
image: "jenkinsciinfra/builder:2.0.7@sha256:8fd127b2abeb94acb34f528cf54007f1718fad9bee40257bad1e3b3ccacc16c6"
resources:
limits: {}
requests:
memory: "4Gi"
cpu: "2"
'''
}
}
environment {
TZ = "UTC"
USE_LOCAL_NODE = "true"
USE_LOCAL_RUBY = "true"
}
triggers {
cron("${env.BRANCH_NAME == 'master' ? 'H/30 * * * *' : ''}")
}
options {
timeout(time: 60, unit: 'MINUTES')
ansiColor('xterm')
disableConcurrentBuilds(abortPrevious: true)
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '5', numToKeepStr: '5')
}
stages {
stage('NPM Install') {
steps {
sh 'npm install'
}
}
stage('Bundle Install') {
steps {
// throw errors if Gemfile has been modified since Gemfile.lock
sh '''
bundle config --global frozen 1
bundle install
'''
}
}
stage('Build') {
steps {
sh 'make'
}
}
stage('Deploy to preview site') {
when {
changeRequest target: 'master'
}
environment {
NETLIFY_AUTH_TOKEN = credentials('netlify-auth-token')
}
post {
success {
recordDeployment('jenkins-infra', 'jenkins.io', pullRequest.head, 'success', "https://deploy-preview-${CHANGE_ID}--jenkins-io-site-pr.netlify.app")
}
failure {
recordDeployment('jenkins-infra', 'jenkins.io', pullRequest.head, 'failure', "https://deploy-preview-${CHANGE_ID}--jenkins-io-site-pr.netlify.app")
}
}
steps {
sh('/usr/local/bin/netlify-deploy --siteName "jenkins-io-site-pr" --title "Preview deploy for ${CHANGE_ID}" --alias "deploy-preview-${CHANGE_ID}" -d ./build/_site')
}
}
}
}