-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: jenkins pipeline support offline
Signed-off-by: Meng JiaFeng <jiafeng.meng@merico.dev>
- Loading branch information
1 parent
b7d1842
commit 5fdf38c
Showing
6 changed files
with
94 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
internal/pkg/plugin/jenkinspipeline/tpl/Jenkinsfile_offline.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
podTemplate(containers: [ | ||
containerTemplate(name: 'maven', image: 'maven:3.8.6-openjdk-18', command: 'sleep', args: '99d'), | ||
containerTemplate(name: 'buildkit', image: 'moby/buildkit:master', ttyEnabled: true, privileged: true), | ||
], volumes: [ | ||
secretVolume(secretName: '[[ .ImageRepoDockerSecret ]]', mountPath: '/root/.docker') | ||
]) { | ||
node(POD_LABEL) { | ||
stage("Get Project") { | ||
checkout scm | ||
} | ||
stage('Run Maven test') { | ||
gitlabCommitStatus("test") { | ||
container('maven') { | ||
stage('run mvn test') { | ||
sh 'mvn -B test' | ||
} | ||
} | ||
} | ||
} | ||
stage("Build Docker image") { | ||
gitlabCommitStatus("build image") { | ||
container('buildkit') { | ||
stage('build a Maven project') { | ||
String opts = "" | ||
String imageRepo = "[[ .imageRepo.user ]]/[[ .AppName ]]" | ||
String imageURL = "[[ .imageRepo.url ]]" | ||
if (imageURL) { | ||
imageRepo = "${imageURL}/${imageRepo}" | ||
} | ||
if (imageRepo.contains("http://")) { | ||
opts = ",registry.insecure=true" | ||
imageRepo = imageRepo.replace("http://", "") | ||
} | ||
String version | ||
if (env.GIT_COMMIT) { | ||
version = env.GIT_COMMIT.substring(0, 8) | ||
} else { | ||
sh "git config --global --add safe.directory '*'" | ||
String gitCommitLang = sh (script: "git log -n 1 --pretty=format:'%H'", returnStdout: true) | ||
version = gitCommitLang.substring(0, 8) | ||
} | ||
sh """ | ||
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${imageRepo}:latest,push=true${opts} | ||
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${imageRepo}:${version},push=true${opts} | ||
""" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters