-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
88 lines (80 loc) · 3.19 KB
/
Jenkinsfile
File metadata and controls
88 lines (80 loc) · 3.19 KB
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
pipeline {
parameters {
string(name: 'BASE_DOCKER_REGISTRY_URL', defaultValue: 'registry.hub.docker.com', description: 'Where should I get the base image?')
string(name: 'BASE_IMAGE_NAME', defaultValue: 'library/alpine', description: 'What is the base image name?')
string(name: 'BASE_IMAGE_TAG', defaultValue: '3.17', description: 'Do we have a speical base image tag?')
string(name: 'DOCKER_REGISTRY_URL', defaultValue: 'harbor.stacktonic.au', description: 'How should I store the image?')
string(name: 'IMAGE_NAME', defaultValue: 'stacktonic/alpine', description: 'How should I store the image?')
string(name: 'IMAGE_TAG', defaultValue: 'latest', description: 'Do we have a speical tag?')
}
agent {
kubernetes {
yaml '''
---
apiVersion: v1
kind: Pod
spec:
containers:
- name: docker
image: docker:dind
securityContext:
privileged: true
env:
- name: DOCKER_TLS_CERTDIR
value: ""
'''
}
}
environment {
BASE_IMAGE_NAME="${params.BASE_IMAGE_NAME}"
BASE_IMAGE_TAG="${params.BASE_IMAGE_TAG}"
BASE_REPOSITORY_URL="${params.BASE_DOCKER_REGISTRY_URL}"
IMAGE_NAME="${params.IMAGE_NAME}"
IMAGE_TAG="${params.IMAGE_TAG}"
REPOSITORY_URL= 'https://git.stacktonic.au/StackTonic/docker-alpine.git'
BRANCH_NAME= 'main'
DOCKER_REGISTRY_URL="${params.DOCKER_REGISTRY_URL}"
}
stages {
stage('Get Code') {
steps {
git branch:'main', url: 'https://git.stacktonic.au/StackTonic/docker-alpine.git'
}
}
stage('Login to Docker registry') {
steps {
container('docker') {
withCredentials([usernamePassword(credentialsId: 'a0cdec83-46ce-49ab-b524-17f748b737db', passwordVariable: 'repo_pass', usernameVariable: 'repo_user')]) {
sh "docker login -u ${repo_user} -p ${repo_pass} ${DOCKER_REGISTRY_URL}"
}
}
}
}
stage('Build') {
steps {
container('docker') {
sh 'printenv'
sh 'docker info'
sh "docker build --network host -t ${IMAGE_NAME}:build-${BUILD_ID} --build-arg BASE_REPOSITORY_URL=${BASE_REPOSITORY_URL} --build-arg BASE_IMAGE_NAME=${BASE_IMAGE_NAME} --build-arg BASE_IMAGE_TAG=${BASE_IMAGE_TAG} ."
}
}
}
stage('Test'){
steps {
sh 'echo Testing'
}
}
stage('Publish to Docker registry') {
steps {
container('docker') {
script {
sh 'docker tag ${IMAGE_NAME}:build-${BUILD_ID} ${DOCKER_REGISTRY_URL}/${IMAGE_NAME}:latest'
sh 'docker tag ${IMAGE_NAME}:build-${BUILD_ID} ${DOCKER_REGISTRY_URL}/${IMAGE_NAME}:build-${BUILD_ID}'
sh 'docker push ${DOCKER_REGISTRY_URL}/${IMAGE_NAME}:build-${BUILD_ID}'
sh 'docker push ${DOCKER_REGISTRY_URL}/${IMAGE_NAME}:latest'
}
}
}
}
}
}