This repository has been archived by the owner on Jan 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkinsfile
109 lines (108 loc) · 3.51 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
pipeline {
agent {
kubernetes {
defaultContainer 'node'
yaml """
kind: Pod
spec:
containers:
- name: node
image: node:15.7.0
command:
- cat
tty: true
- name: kaniko
image: gcr.io/kaniko-project/executor:v1.5.1-debug
command:
- /busybox/cat
tty: true
securityContext:
allowPrivilegeEscalation: false
volumeMounts:
- name: jenkins-docker-cfg
mountPath: /kaniko/.docker
volumes:
- name: jenkins-docker-cfg
projected:
sources:
- secret:
name: gitlab-polkabtc-ui-registry
items:
- key: .dockerconfigjson
path: config.json
"""
}
}
environment {
CI = 'true'
DISCORD_WEBHOOK_URL = credentials('discord_webhook_url')
GITHUB_TOKEN = credentials('ns212-github-token')
}
options {
timestamps()
ansiColor('xterm')
}
stages {
stage('Prepare') {
steps {
sh script: 'apt-get update && apt-get install -y libusb-1.0-0-dev libudev-dev', label: 'Install linux dependencies'
sh 'ln -s .env.${BRANCH_NAME:-dev} .env'
sh 'yarn install'
sh 'yarn lint'
}
}
stage('Test') {
steps {
sh 'yarn test'
}
}
stage('Build') {
steps {
sh 'yarn build'
stash(name: 'yarn_build', includes: 'DockerfileProd, nginx.conf, build/')
}
}
stage('Build docker image') {
environment {
PATH = "/busybox:$PATH"
REGISTRY = 'registry.gitlab.com' // Configure your own registry
REPOSITORY = 'interlay'
IMAGE = 'polkabtc-ui'
}
steps {
container(name: 'kaniko', shell: '/busybox/sh') {
dir('unstash') {
unstash("yarn_build")
sh '''#!/busybox/sh
GIT_BRANCH_SLUG=$(echo $BRANCH_NAME | sed -e 's/\\//-/g')
/kaniko/executor -f `pwd`/DockerfileProd -c `pwd` \
--destination=${REGISTRY}/${REPOSITORY}/${IMAGE}:${GIT_BRANCH_SLUG} \
--destination=${REGISTRY}/${REPOSITORY}/${IMAGE}:${GIT_BRANCH_SLUG}-${GIT_COMMIT:0:6}-$(date +%s)
'''
}
}
}
}
stage('Create GitHub release') {
when {
anyOf {
tag '*'
}
}
steps {
sh '''
wget -q -O - https://github.com/git-chglog/git-chglog/releases/download/v0.10.0/git-chglog_0.10.0_linux_amd64.tar.gz | tar xzf -
./git-chglog --output CHANGELOG.md $TAG_NAME
wget -q -O - https://github.com/cli/cli/releases/download/v1.6.2/gh_1.6.2_linux_amd64.tar.gz | tar xzf -
./gh_1.6.2_linux_amd64/bin/gh auth status
./gh_1.6.2_linux_amd64/bin/gh release -R $GIT_URL create $TAG_NAME --title $TAG_NAME -F CHANGELOG.md -d
'''
}
}
}
post {
always {
discordSend description: "Jenkins Pipeline Build", footer: "Footer Text", link: env.BUILD_URL, result: currentBuild.currentResult, title: JOB_NAME, webhookURL: env.DISCORD_WEBHOOK_URL
}
}
}