-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.template
100 lines (100 loc) · 4.76 KB
/
Jenkinsfile.template
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
pipeline {
agent none
triggers{
upstream(upstreamProjects: 'UCSB-PSTAT GitHub/base-rstudio/main', threshold: hudson.model.Result.SUCCESS)
}
environment {
IMAGE_NAME = '<COURSE/IMAGE ID>'
}
stages {
stage('Build Test Deploy') {
agent {
kubernetes {
cloud 'rke-test'
inheritFrom 'podman'
}
}
stages{
stage('Build') {
steps {
script {
if (currentBuild.getBuildCauses('com.cloudbees.jenkins.GitHubPushCause').size() || currentBuild.getBuildCauses('jenkins.branch.BranchIndexingCause').size()) {
scmSkip(deleteBuild: true, skipPattern:'.*\\[ci skip\\].*')
}
}
container('podman') {
echo "NODE_NAME = ${env.NODE_NAME}"
sh 'podman build -t localhost/$IMAGE_NAME --pull --force-rm --no-cache .'
}
}
post {
unsuccessful {
container('podman') {
sh 'podman rmi -i localhost/$IMAGE_NAME || true'
}
}
}
}
stage('Test') {
steps {
container('podman') {
sh 'podman run -it --rm --pull=never localhost/$IMAGE_NAME which rstudio'
sh 'podman run -it --rm --pull=never localhost/$IMAGE_NAME R -q -e "getRversion() >= \\"4.1.3\\"" | tee /dev/stderr | grep -q "TRUE"'
//sh 'podman run -it --rm --pull=never localhost/$IMAGE_NAME R -e "library(\"<library>\");library(\"<library>\")"'
sh 'podman run -d --name=$IMAGE_NAME --rm --pull=never -p 8888:8888 localhost/$IMAGE_NAME start-notebook.sh --NotebookApp.token="jenkinstest"'
sh 'sleep 10 && curl -v http://localhost:8888/rstudio?token=jenkinstest 2>&1 | grep -P "HTTP\\S+\\s[1-3][0-9][0-9]\\s+[\\w\\s]+\\s*$"'
sh 'curl -v http://localhost:8888/lab?token=jenkinstest 2>&1 | grep -P "HTTP\\S+\\s200\\s+[\\w\\s]+\\s*$"'
sh 'curl -v http://localhost:8888/tree?token=jenkinstest 2>&1 | grep -P "HTTP\\S+\\s200\\s+[\\w\\s]+\\s*$"'
}
}
post {
always {
container('podman') {
sh 'podman rm -ifv $IMAGE_NAME'
}
}
unsuccessful {
container('podman') {
sh 'podman rmi -i localhost/$IMAGE_NAME || true'
}
}
}
}
stage('Deploy') {
when { branch 'main' }
environment {
DOCKER_HUB_CREDS = credentials('DockerHubToken')
}
steps {
container('podman') {
sh 'skopeo copy containers-storage:localhost/$IMAGE_NAME docker://docker.io/ucsb/$IMAGE_NAME:latest --dest-username $DOCKER_HUB_CREDS_USR --dest-password $DOCKER_HUB_CREDS_PSW'
sh 'skopeo copy containers-storage:localhost/$IMAGE_NAME docker://docker.io/ucsb/$IMAGE_NAME:v$(date "+%Y%m%d") --dest-username $DOCKER_HUB_CREDS_USR --dest-password $DOCKER_HUB_CREDS_PSW'
}
}
post {
always {
container('podman') {
sh 'podman rmi -i localhost/$IMAGE_NAME || true'
}
}
}
}
}
post {
always {
container('podman') {
sh 'podman rmi -i localhost/$IMAGE_NAME || true'
}
}
}
}
}
post {
success {
slackSend(channel: '#infrastructure-build', username: 'jenkins', color: 'good', message: "Build ${env.JOB_NAME} ${env.BUILD_NUMBER} just finished successfull! (<${env.BUILD_URL}|Details>)")
}
failure {
slackSend(channel: '#infrastructure-build', username: 'jenkins', color: 'danger', message: "Uh Oh! Build ${env.JOB_NAME} ${env.BUILD_NUMBER} had a failure! (<${env.BUILD_URL}|Find out why>).")
}
}
}