-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
83 lines (80 loc) · 1.87 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
pipeline {
libraries {
lib 'jenkins_pipeline_shared@main'
}
environment {
imagename = 'harbor.kacsh.com/library/tf-tools'
registryCredential = 'harbor-docker'
dockerImage = ''
registryUri = 'https://harbor.kacsh.com'
imageLine = 'harbor.kacsh.com/library/tf-tools:pre-latest'
}
agent {
kubernetes {
label 'jenkins-worker'
defaultContainer 'docker'
yamlFile 'jenkins.yaml'
}
}
stages {
stage ('Start') {
steps {
// send build started notifications
sendNotifications 'STARTED'
}
}
stage('Cloning Git') {
steps {
git([url: 'https://github.com/kkacsh321/tf-tools.git', branch: 'main', credentialsId: 'kkacsh321-github'])
}
}
stage('Building image') {
steps{
script {
dockerImage = docker.build imagename
}
}
}
stage('Push Image to be scanned') {
steps{
script {
docker.withRegistry( registryUri, registryCredential ) {
dockerImage.push('pre-latest')
}
}
}
}
stage('Analyze with Anchore plugin') {
steps {
writeFile file: 'anchore_images', text: imageLine
anchore bailOnFail: false, engineRetries: '1800', name: 'anchore_images'
}
}
stage('Publish Latest Image') {
steps{
script {
docker.withRegistry( registryUri, registryCredential ) {
dockerImage.push('latest')
dockerImage.push('$BUILD_NUMBER')
}
}
}
}
stage('Remove Unused docker image') {
steps{
sh "docker rmi $imagename:$BUILD_NUMBER"
}
}
stage('Add property file') {
steps{
sh "echo $BUILD_NUMBER > build.properties"
archive 'build.properties'
}
}
}
post {
always {
sendNotifications currentBuild.result
}
}
}