-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathJenkinsfile
75 lines (66 loc) · 2.6 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
def gitBranch = env.BRANCH_NAME
def imageName = "memphis-rest-gateway"
def gitURL = "[email protected]:Memphisdev/memphis-rest-gateway.git"
def repoUrlPrefix = "memphisos"
node ("memphis-jenkins-big-fleet,") {
git credentialsId: 'main-github', url: gitURL, branch: gitBranch
def versionTag = readFile "./version.conf"
try{
stage('Login to Docker Hub') {
withCredentials([usernamePassword(credentialsId: 'docker-hub', usernameVariable: 'DOCKER_HUB_CREDS_USR', passwordVariable: 'DOCKER_HUB_CREDS_PSW')]) {
sh 'docker login -u $DOCKER_HUB_CREDS_USR -p $DOCKER_HUB_CREDS_PSW'
}
}
if (env.BRANCH_NAME ==~ /(latest)/) {
stage('Build and push image to Docker Hub') {
sh "docker buildx use builder"
sh "docker buildx build --push --tag ${repoUrlPrefix}/${imageName}:${gitBranch} --tag ${repoUrlPrefix}/${imageName}:${versionTag} --platform linux/amd64,linux/arm64 ."
}
}
else {
stage('Build and push image to Docker Hub') {
sh "docker buildx use builder"
sh "docker buildx build --push --tag ${repoUrlPrefix}/${imageName}-test:${gitBranch} --platform linux/amd64,linux/arm64 ."
}
}
if (env.BRANCH_NAME ==~ /(latest)/) {
stage('checkout to version branch'){
withCredentials([sshUserPrivateKey(keyFileVariable:'check',credentialsId: 'main-github')]) {
sh "git reset --hard origin/latest"
sh "GIT_SSH_COMMAND='ssh -i $check' git checkout -b ${versionTag}"
sh "GIT_SSH_COMMAND='ssh -i $check' git push --set-upstream origin ${versionTag}"
}
}
stage('Create new release') {
sh 'sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo -y'
sh 'sudo dnf install gh -y'
withCredentials([string(credentialsId: 'gh_token', variable: 'GH_TOKEN')]) {
sh "gh release create ${versionTag} --generate-notes"
}
}
}
notifySuccessful()
}
catch (e) {
currentBuild.result = "FAILED"
cleanWs()
notifyFailed()
throw e
}
}
def notifySuccessful() {
emailext (
subject: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':
Check console output and connection attributes at ${env.BUILD_URL}""",
recipientProviders: [requestor()]
)
}
def notifyFailed() {
emailext (
subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':
Check console output at ${env.BUILD_URL}""",
recipientProviders: [requestor()]
)
}