-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
49 lines (43 loc) · 1.48 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
node {
checkout scm
def REPO = params.imageRepo
def GIT_COMMIT = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
def DEPLOY_TAG = "$REPO:$GIT_COMMIT"
def FAST_PATH = ''
stage('Fastpath') {
sh 'wget https://docker-fastpath.s3-eu-west-1.amazonaws.com/releases/linux/docker-fastpath-linux-amd64-latest.tgz'
sh 'tar xzvf docker-fastpath-linux-amd64-latest.tgz'
sh 'rm docker-fastpath-linux-amd64-latest.tgz'
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'dockerhub',
usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD']]) {
FAST_PATH = sh(script: "./fastpath --verbose HEAD $REPO", returnStdout: true).trim()
}
}
stage('Build') {
if (FAST_PATH == '') {
echo "New code. Building..."
sh "docker build -t $DEPLOY_TAG ."
} else {
DEPLOY_TAG = "$REPO:$FAST_PATH"
echo "Found a suitable image: $DEPLOY_TAG"
}
}
stage('Test') {
if (FAST_PATH == '') {
echo 'Do some tests...'
}
}
stage('Push') {
if (FAST_PATH == '') {
echo "Pushing $DEPLOY_TAG to the registry"
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'dockerhub',
usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD']]) {
sh 'docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"'
sh "docker push $DEPLOY_TAG"
}
}
}
stage('Deploy') {
echo "Deploy $DEPLOY_TAG (placeholder)"
}
}