-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile-slave-image
49 lines (44 loc) · 2.14 KB
/
Jenkinsfile-slave-image
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
#!groovy
def timestamp = java.time.Instant.now().toEpochMilli();
def imageFinalName = "jettyproject/jetty-build-agent:"+timestamp
pipeline {
agent any
options {
durabilityHint('PERFORMANCE_OPTIMIZED')
buildDiscarder logRotator( numToKeepStr: '30' )
}
triggers {
cron '@weekly'
}
stages {
stage("Docker build and push") {
agent { node { label 'linux' } }
steps {
withCredentials([usernamePassword(credentialsId: 'DockerHubPwd', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD'),
usernamePassword(credentialsId: 'nexus-cred', usernameVariable: 'USERNAME_NEXUS', passwordVariable: 'PASSWORD_NEXUS')]) {
// sh "docker login -u $USERNAME -p $PASSWORD"
sh "docker build --no-cache --tag=jetty-build-agent:latest slave-image/"
// sh "docker tag jetty-build-agent:latest $imageFinalName"
// sh "docker push $imageFinalName"
// sh "docker logout"
sh "docker login -u $USERNAME_NEXUS -p '$PASSWORD_NEXUS' 10.0.0.12:8083"
sh "docker tag jetty-build-agent:latest 10.0.0.12:8083/$imageFinalName"
sh "docker push 10.0.0.12:8083/$imageFinalName"
//sh "docker logout"
script {
def cloudName = "kubernetes-no-docker" // "kubernetes"
def templateName = "jenkins-slave-no-docker"
def containerName = "jnlp"
def imageName = Jenkins.instance.clouds.getByName(cloudName).templates.find { it.name.equals(templateName) }.containers.find { it.name.equals(containerName) }.image;
echo "imageName before: $imageName"
Jenkins.instance.clouds.getByName(cloudName).templates.find { it.name.equals(templateName) }.containers.find { it.name.equals(containerName) }.image = imageFinalName;
Jenkins.instance.save()
imageName = Jenkins.instance.clouds.getByName(cloudName).templates.find { it.name.equals(templateName) }.containers.find { it.name.equals(containerName) }.image;
echo "imageName after: $imageName"
}
}
}
}
}
}
// vim: et:ts=2:sw=2:ft=groovy