Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example showing how to build project inside docker container #83

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
node {
stage('checkout') {
git url: 'https://repository.com/foo/golang-project.git'
}
stage("build") {
writeFile file: "test.txt", text: "test"
docker.withRegistry("https://my-private-registry.intranet.net", 'docker-registry-credentials') {
docker.image("my-private-registry.intranet.net/tool/golang").inside("-v /home/jenkins/foo.txt:/foo.txt") { c ->
sh 'cat /foo.txt' // we can mount any file from host
sh 'cat test.txt' // we can access files from workspace
sh 'echo "modified-inside-container" > test.txt' // we can modify files in workspace
sh 'go build' // we can run command from docker image
sh 'printenv' // jenkins is passing all envs variables into container
}
}
sh 'cat test.txt' // will be "modified-inside-container" here
}
}
6 changes: 6 additions & 0 deletions pipeline-examples/build-in-docker-container/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Synopsis

This is very simple example showing how to build project inside docker container using image coming from private docker registry.

docker-registry-credentials is credentials id configured as username/password in jenkins.