This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Jenkinsfile
109 lines (91 loc) · 4.44 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
#!groovy
pipeline {
agent {
label "docker-build"
}
triggers {
issueCommentTrigger('trigger_build')
upstream(upstreamProjects: "Codewind/codewind-installer/${env.BRANCH_NAME}, Codewind/codewind-filewatchers/${env.BRANCH_NAME}", threshold: hudson.model.Result.SUCCESS)
}
options {
timestamps()
skipStagesAfterUnstable()
}
stages {
stage('Build Docker image') {
steps {
// NOTE: change of this sh call should be in sync with
// './scripts/build.sh' and './codewind-che-sidecar/build.sh'.
sh '''#!/usr/bin/env bash
echo "Starting build the Codewind Che plugin sidecar container..."
set -eu
BLUE='\033[1;34m'
NC='\033[0m'
# Build the sidecar image
printf "${BLUE}Building the Codewind sidecar image${NC}\n"
cd ./codewind-che-sidecar
# Extract the filewatcherd codebase
if [ -d "codewind-filewatchers" ]; then
rm -rf codewind-filewatchers
fi
export INSTALLER_REPO="https://github.com/eclipse/codewind-installer.git"
export CW_CLI_BRANCH=master
# the command below will echo the head commit if the branch exists, else it just exits
if [[ -n \$(git ls-remote --heads \$INSTALLER_REPO ${BRANCH_NAME}) ]]; then
echo "Will use matching ${BRANCH_NAME} branch on \$INSTALLER_REPO"
export CW_CLI_BRANCH=${BRANCH_NAME}
else
# Optionally, we could use CHANGE_TARGET here, if defined, which contains the branch name of the PR target (eg master).
echo "No matching branch on \$INSTALLER_REPO (of ${BRANCH_NAME}) - using \$CW_CLI_BRANCH branch"
fi
git clone https://github.com/eclipse/codewind-filewatchers.git
# We use --no-cache here because we are consuming cwctl from an external resource (which we should never cache)
docker build --no-cache --build-arg CW_CLI_BRANCH=$CW_CLI_BRANCH -t codewind-che-sidecar .
'''
}
}
stage('Publish Docker image') {
// This when clause disables PR build uploads; you may comment this out if you want your build uploaded.
when {
beforeAgent true
not {
changeRequest()
}
}
steps {
withDockerRegistry([url: 'https://index.docker.io/v1/', credentialsId: 'docker.com-bot']) {
sh '''#!/usr/bin/env bash
if [[ $GIT_BRANCH == "master" ]]; then
TAG="latest"
else
TAG=$GIT_BRANCH
fi
# Publish docker images with a filter for branch name
# Acceptable branch names: master, start with '<number>.<number>'
if [[ $GIT_BRANCH == "master" ]] || [[ $GIT_BRANCH =~ ^([0-9]+\\.[0-9]+) ]]; then
echo "Publishing docker images for Eclipse Codewind Che Sidecar..."
echo "publish.sh eclipse $TAG"
./scripts/publish.sh eclipse $TAG
if [[ $GIT_BRANCH =~ ^([0-9]+\\.[0-9]+) ]]; then
IFS='.' # set '.' as delimiter
read -ra TOKENS <<< "$GIT_BRANCH"
IFS=' ' # reset delimiter
export TAG_CUMULATIVE=${TOKENS[0]}.${TOKENS[1]}
echo "publish.sh eclipse $TAG_CUMULATIVE"
./scripts/publish.sh eclipse $TAG_CUMULATIVE
fi
else
echo "Skip publishing docker images for $GIT_BRANCH branch"
fi
'''
}
}
}
}
post {
always {
echo 'Clean up workspace'
deleteDir() /* clean up our workspace */
}
}
}