I've got Jenkins running in a docker container, with swarm agents.
I've created a docker volume: 'maven-repository' and can get a job to access this (to cache maven). However, if two jobs run simultaneously I get a permission denied error, sample logs below:
Anyone else had this issue and managed to solve it? I've also tried mounting /var/jenkins_home/.m2:/tmp/.m2
Successful run:
Running on Jenkins in /var/jenkins_home/workspace/Alex Test
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Agent Setup)
[Pipeline] sh
[Alex Test] Running shell script
+ docker pull maven:3.5.3-jdk-8-alpine
3.5.3-jdk-8-alpine: Pulling from library/maven
Digest: sha256:d8c6a5fef17ae7fcb2629e558554a085e90c722796306f31bee7fb7b9a5a123e
Status: Image is up to date for maven:3.5.3-jdk-8-alpine
[Pipeline] }
[Pipeline] // stage
[Pipeline] sh
[Alex Test] Running shell script
+ docker inspect -f . maven:3.5.3-jdk-8-alpine
.
[Pipeline] withDockerContainer
Jenkins seems to be running inside container 73c7522e3a5de318e5500a6092974cc78ab5eedf4de70b18d264aeb40e40b360
$ docker run -t -d -u 1000:1000 --privileged -v maven-repository:/tmp/.m2 -v /var/run/docker.sock:/var/run/docker.sock -w "/var/jenkins_home/workspace/Alex Test" --volumes-from 73c7522e3a5de318e5500a6092974cc78ab5eedf4de70b18d264aeb40e40b360 -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** maven:3.5.3-jdk-8-alpine cat
$ docker top 9902bb5b16a8b5a0b5ee16f2a0c87ea9961fe06c895b859f96142adf388be1b9 -eo pid,comm
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Check Maven Directory)
[Pipeline] sh
[Alex Test] Running shell script
+ ls /tmp
[Pipeline] sh
[Alex Test] Running shell script
+ ls /tmp/.m2
hsperfdata_root
repository
[Pipeline] sh
[Alex Test] Running shell script
+ cat /dev/urandom
+ fold -w 32
+ head -n 1
+ tr -dc a-zA-Z0-9
+ touch /tmp/.m2/68rS0lsIiml0cIg2bJ8BooxltUqJy31X
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
$ docker stop --time=1 9902bb5b16a8b5a0b5ee16f2a0c87ea9961fe06c895b859f96142adf388be1b9
$ docker rm -f 9902bb5b16a8b5a0b5ee16f2a0c87ea9961fe06c895b859f96142adf388be1b9
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
If a Job is run at the same time:
[Pipeline] withDockerContainer
swarm-agent seems to be running inside container 9475a72289efb2b4a0918fa5127514e81bea82b90720dd859380fe9ffc1f4d92
$ docker run -t -d -u 10000:10000 --privileged -v maven-repository:/tmp/.m2 -v /var/run/docker.sock:/var/run/docker.sock -w "/home/jenkins/agent/workspace/Alex Test#3" --volumes-from 9475a72289efb2b4a0918fa5127514e81bea82b90720dd859380fe9ffc1f4d92 -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** maven:3.5.3-jdk-8-alpine cat
$ docker top b7b9793e52ae9497209b7469c936e98d157d408ad5235776e26b3c05c2a151da -eo pid,comm
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Check Maven Directory)
[Pipeline] sh
[Alex Test#3] Running shell script
+ ls /tmp
[Pipeline] sh
[Alex Test#3] Running shell script
+ ls /tmp/.m2
[Pipeline] sh
[Alex Test#3] Running shell script
+ fold -w 32
+ cat /dev/urandom
+ tr -dc a-zA-Z0-9
+ head -n 1
+ touch /tmp/.m2/8lqaDHloPUqmw6a4Wr3aky7AZdDhMIrW
touch: /tmp/.m2/8lqaDHloPUqmw6a4Wr3aky7AZdDhMIrW: Permission denied
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
$ docker stop --time=1 b7b9793e52ae9497209b7469c936e98d157d408ad5235776e26b3c05c2a151da
$ docker rm -f b7b9793e52ae9497209b7469c936e98d157d408ad5235776e26b3c05c2a151da
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE
We found that the master was running our first job which has the docker volume, however running multiple jobs caused the slave to be used which did not have the docker volume present.
Related
I am trying to get into Jenkins but I am now stuck in the first step of the tutorial https://www.jenkins.io/doc/pipeline/tour/hello-world/ for hours.
I installed JDK and Docker Desktop as instructed on Windows machine. For Docker Desktop I also needed to install WSL 2 with Ubuntu.
I have created a sample GitHub Repo with only a Jenkinsfile containing the sample code from the tutorial:
/* Requires the Docker Pipeline plugin */
pipeline {
agent { docker { image 'python:3.10.7-alpine' } }
stages {
stage('build') {
steps {
sh 'python --version'
}
}
}
}
If I start a Jenkins pipeline connected to the GitHub repository and try to build it, I get the following error:
13:01:46 Connecting to https://api.github.com with no credentials, anonymous access
Obtained Jenkinsfile from 7533f199524c45c20290f15d17d103958b24abc3
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in C:\Users\wenni\.jenkins\workspace\FirstPipeline_main
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
The recommended git tool is: NONE
No credentials specified
> C:\Program Files\Git\cmd\git.exe rev-parse --resolve-git-dir C:\Users\wenni\.jenkins\workspace\FirstPipeline_main\.git # timeout=10
Fetching changes from the remote Git repository
> C:\Program Files\Git\cmd\git.exe config remote.origin.url https://github.com/Wagnerd6/JenkinsPipelineTest.git # timeout=10
Fetching without tags
Fetching upstream changes from https://github.com/Wagnerd6/JenkinsPipelineTest.git
> C:\Program Files\Git\cmd\git.exe --version # timeout=10
> git --version # 'git version 2.38.1.windows.1'
> C:\Program Files\Git\cmd\git.exe fetch --no-tags --force --progress -- https://github.com/Wagnerd6/JenkinsPipelineTest.git +refs/heads/main:refs/remotes/origin/main # timeout=10
Checking out Revision 7533f199524c45c20290f15d17d103958b24abc3 (main)
> C:\Program Files\Git\cmd\git.exe config core.sparsecheckout # timeout=10
> C:\Program Files\Git\cmd\git.exe checkout -f 7533f199524c45c20290f15d17d103958b24abc3 # timeout=10
Commit message: "Python docker img"
> C:\Program Files\Git\cmd\git.exe rev-list --no-walk e7de46ec1626389bb4e5c5577013ebaa8f214de2 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] isUnix
[Pipeline] withEnv
[Pipeline] {
[Pipeline] bat
C:\Users\wenni\.jenkins\workspace\FirstPipeline_main>docker inspect -f . "python:3.10.7-alpine"
.
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container
$ docker run -d -t -w C:/Users/wenni/.jenkins/workspace/FirstPipeline_main/ -v C:/Users/wenni/.jenkins/workspace/FirstPipeline_main/:C:/Users/wenni/.jenkins/workspace/FirstPipeline_main/ -v C:/Users/wenni/.jenkins/workspace/FirstPipeline_main#tmp/:C:/Users/wenni/.jenkins/workspace/FirstPipeline_main#tmp/ -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** python:3.10.7-alpine cmd.exe
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.io.IOException: Failed to run image 'python:3.10.7-alpine'. Error: docker: Error response from daemon: the working directory 'C:/Users/wenni/.jenkins/workspace/FirstPipeline_main/' is invalid, it needs to be an absolute path.
See 'docker run --help'.
at org.jenkinsci.plugins.docker.workflow.client.WindowsDockerClient.run(WindowsDockerClient.java:58)
at org.jenkinsci.plugins.docker.workflow.WithContainerStep$Execution.start(WithContainerStep.java:200)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:322)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:196)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:124)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:47)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(Docker.groovy:140)
at org.jenkinsci.plugins.docker.workflow.Docker.node(Docker.groovy:66)
at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(Docker.groovy:125)
at org.jenkinsci.plugins.docker.workflow.declarative.DockerPipelineScript.runImage(DockerPipelineScript.groovy:54)
at org.jenkinsci.plugins.docker.workflow.declarative.AbstractDockerPipelineScript.configureRegistry(AbstractDockerPipelineScript.groovy:63)
at org.jenkinsci.plugins.docker.workflow.declarative.AbstractDockerPipelineScript.run(AbstractDockerPipelineScript.groovy:50)
at org.jenkinsci.plugins.pipeline.modeldefinition.agent.CheckoutScript.checkoutAndRun(CheckoutScript.groovy:61)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:90)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
at jdk.internal.reflect.GeneratedMethodAccessor125.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:46)
at com.cloudbees.groovy.cps.Next.step(Next.java:83)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:177)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:166)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:136)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:275)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:166)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:187)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:420)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:95)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:330)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:294)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:30)
at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:70)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
Finished: FAILURE
When I replace the agent { docker { image 'python:3.10.7-alpine' } } with agent any the build works but of course fails on python --version as Python is not installed.
My research only led me to there being a problem with Windows and running the Docker containers. Is it really not possible to simply follow the first tutorial page of Jenkins on a Windows machine?
Unfortunately the agent "docker" is not compatible in a Windows hosted Linux environment.
This is a known Problem for quiet a while and any effort to make a lasting fix failed.
The main problem is the incompatibility between Windows and Linux File paths.
Hence the often reported Error:
"Error: docker: Error response from daemon: the working directory 'C:/Jenkins/workspace/testspace/' is invalid, it needs to be an absolute path."
The only way to quickly advance in the Jenkins tutorial is to use Docker CLI (Command Line) commands.
A basic example to continue the tutorial looks like this:
pipeline {
agent any
stages {
stage('build') {
steps {
script {
/* the return value gets caught and saved into the variable MY_CONTAINER */
MY_CONTAINER = bat(script: '#docker run -d -i python:3.10.7-alpine', returnStdout: true).trim()
echo "mycontainer_id is ${MY_CONTAINER}"
/* python --version gets executed inside the Container */
bat "docker exec ${MY_CONTAINER} python --version "
/* the Container gets removed */
bat "docker rm -f ${MY_CONTAINER}"
}
}
}
}
}
There are two major changes compared to the Jenkins tutorial script:
instead of sh Windows-based systems should use bat for executing batch commands.
avoiding the agent "docker" and replacing it with any
I would like to echo out the .env.list values used in the docker run command in Jenkins, I have tried as follows echo "Print the env.list file: ${.env.list}"
Could someone please advise how can I print the .env.list file in docker run command
sh """
docker run --env-file bookpro-co/.env.list ${baseUrlConfig} \
-v \"${ARTEFACT_DIR}:/artefacts\" \
-v \"${env.WORKSPACE}/bookpro-co:/bookpro-test\" \
cypress:latest \
/node_modules/.bin/cypress-tags ${cypressArgs}
echo "Print the env.list file: ${.env.list}"
"""
I created an alias as a part of my docker image and put the command in ~/.bashrc. The alias is really simple. Just has to run the script that was installed during the image build. When I ran the docker container in my local machine, I was able to see the alias. Also in jenkins pipeline, when I ran the cat the bashrc, I was able to see the alias command. This is my dockerfile.
FROM ros:melodic-ros-core-stretch
RUN apt-get update
COPY ./scripts /scripts
RUN cat scripts/alias.sh > ~/.bashrc
RUN bash scripts/install-tools.bash
This is how install-tools.bash looks like.
#!/bin/bash
mkdir -p /opt/scripts
install --mode=755 --group=root --owner=root /scripts/pre-build.bash /opt/scripts/
rm -rf /scripts
This is how alias.sh looks like.
alias pre-build="bash /opt/scripts/pre-build.bash"
This is how the Jenkinsfile looks like.
pipeline {
agent {
docker {
args '--network host -u root:root'
image <private repo from dockerhub>
registryCredentialsId 'docker-credentials'
registryUrl 'https://registry.hub.docker.com'
}
}
stages {
stage ('Test') {
steps {
sh '''#!/bin/bash
pre-build
'''
}
}
}
post {
always {
cleanWs()
}
}
}
This is the error I'm getting from jenkins.
Started by user Automated Build Environment
Obtained Jenkinsfile from git https://github.com/<Organization>/test_pkg
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/test_pkg
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
using credential 205a054c-54a3-4cb3-9a7f-519516cc3050
Cloning the remote Git repository
Cloning repository https://github.com/<Organization>/test_pkg
> git init /var/lib/jenkins/workspace/test_pkg # timeout=10
Fetching upstream changes from https://github.com/<Organization>/test_pkg
> git --version # timeout=10
using GIT_ASKPASS to set credentials
> git fetch --tags --progress https://github.com/<Organization>/test_pkg +refs/heads/*:refs/remotes/origin/*
> git config remote.origin.url https://github.com/<Organization>/test_pkg # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
> git config remote.origin.url https://github.com/<Organization>/test_pkg # timeout=10
Fetching upstream changes from https://github.com/<Organization>/test_pkg
using GIT_ASKPASS to set credentials
> git fetch --tags --progress https://github.com/<Organization>/test_pkg +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 514613afaf7c8be82bd20e219c062f7a4b3fb733 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 514613afaf7c8be82bd20e219c062f7a4b3fb733
Commit message: "Update Jenkinsfile"
> git rev-list --no-walk 8c840617b0aed9ae50d00700192ed3573bb1c0d4 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] withDockerRegistry
$ docker login -u <private docker hub username> -p ******** https://registry.hub.docker.com
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /var/lib/jenkins/workspace/test_pkg#tmp/98982a2f-21bf-4460-9dab-d13f8ddba164/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[Pipeline] {
[Pipeline] sh
+ docker inspect -f . <private docker hub repo>
Error: No such object: <private docker hub repo>
[Pipeline] sh
+ docker inspect -f . registry.hub.docker.com/<private docker hub repo>
.
[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 125:130 --network host -u root:root -w /var/lib/jenkins/workspace/test_pkg -v /var/lib/jenkins/workspace/test_pkg:/var/lib/jenkins/workspace/test_pkg:rw,z -v /var/lib/jenkins/workspace/test_pkg#tmp:/var/lib/jenkins/workspace/test_pkg#tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** registry.hub.docker.com/<private docker hub repo> cat
$ docker top 657db353b9e3249c87468eafdeae64246f6b2b1ebeb1cd5ed00c618fc8f1691c -eo pid,comm
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] sh
/var/lib/jenkins/workspace/test_pkg#tmp/durable-e7036032/script.sh: line 2: pre-build: command not found
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] cleanWs
[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Deferred wipeout is used...
[WS-CLEANUP] done
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
$ docker stop --time=1 657db353b9e3249c87468eafdeae64246f6b2b1ebeb1cd5ed00c618fc8f1691c
$ docker rm -f 657db353b9e3249c87468eafdeae64246f6b2b1ebeb1cd5ed00c618fc8f1691c
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withDockerRegistry
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE
I'm trying to find out how to add aliases to docker image that I can access in Jenkinsfile while running a declarative pipeline.
You should broadly assume .bashrc and similar dotfiles don’t work in Docker. There are many common paths to run Docker commands that either don’t run shells at all or run them in a way that doesn’t read dotfiles:
docker run --rm myimage some command
directly runs some command without invoking a shell at all. Even if you explicitly use sh -c "some command" that won’t read shell dotfiles.
You don’t need alias declarations like the one you show, especially in Docker. Just install the script into some directory that’s already in $PATH, like /usr/local/bin.
COPY ./scripts /usr/local/bin/
You didn't run bash, you ran sh with the first command being a comment referring to /bin/bash in the following:
sh '''#!/bin/bash
pre-build
'''
If you want to run bash, try something like:
sh "/bin/bash -c 'pre-build'"
You may also need to configure bash to act like a login shell to get it to process all the normal login files like the .bashrc:
sh "/bin/bash -l -c 'pre-build'"
Goal:
On a Windows Jenkins node, I'd like to clone a GitHub project within a Windows docker container and run maven commands using a Jenkinsfile.
Problem:
I am unable to spin up my Docker container in Jenkins because of an invalid volume specification. Does anyone know a workaround or how to fix this issue?
Details:
Currently, I have a declarative pipeline with an outline like so:
/**
* Defines declarative pipelne for a standard maven build.
*/
def call(body) {
def config = [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body()
pipeline {
agent {
label "WINDOWS-64-DOCKER"
}
stages {
stage('Maven') {
agent {
docker {
image 'enterprise-repos.net/my-org/windows-maven3-jdk7'
reuseNode true
}
}
steps {
script {
def script = "mvn clean install"
sh returnStdout: false, script: script
}
}
}
}
}
}
In Jenkins, it generates the following command:
Windows_Docker does not seem to be running inside a container
$ docker run -t -d -u 18:18 -w c:\jenkins\workspace\git_hub_project
-v c:\jenkins\workspace\git_hub_project:c:\jenkins\workspace\git_hub_project:rw,z
-v c:\jenkins\workspace\git_hub_project#tmp:c:\jenkins\workspace\git_hub_project#tmp:rw,z
-e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ********
-e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ********
-e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ********
-e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ********
-e ******** -e ******** -e ******** -e ******** -e ******** -e ********
enterprise-repos.net/my-org/windows-maven3-jdk7 cat
The error:
java.io.IOException: Failed to run image 'enterprise-repos.net/my-org/windows-maven3-jdk7'. Error: docker:
Error response from daemon: invalid volume specification: 'c:\jenkins\workspace\git_hub_project:c:\jenkins\workspace\git_hub_project:rw,z'.
See 'docker run --help'.
Path Environment Variable for Windows Jenkins Node:
C:\Program Files\java\jre1.8.0_172\bin;
C:\Windows\Sun\Java\bin;
C:\Windows\system32;
C:\Windows;
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Windows\System32\OpenSSH\;
C:\Program Files\Docker;
C:\ProgramData\chocolatey\bin;
C:\Program Files\Git\cmd;
C:\Users\jenkins\AppData\Local\Microsoft\WindowsApps;
C:\Program Files\Git\mingw64\bin;
C:\Program Files\Git\usr\bin;
C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;
.
Docker Version:
Client:
Version: 18.09.0
API version: 1.39
Go version: go1.10.3
Git commit: 33a45cd0a2
Built: unknown-buildtime
OS/Arch: windows/amd64
Experimental: false
Server:
Engine:
Version: 18.09.0
API version: 1.39 (minimum version 1.24)
Go version: go1.10.3
Git commit: 33a45cd0a2
Built: 11/07/2018 00:24:12
OS/Arch: windows/amd64
Experimental: false
Speculation: With my current understanding, I'm not sure how this the docker command is generated, but I believe my issue is the z flag after the rw,z since the Jenkins node is a Windows and the Docker image is also Windows. Any help or suggestions would be lovely.
I am fairly new to Jenkins and Docker, and I am hitting a problem trying to get a docker image of maven to build my project.
My Jenkins script is fairly straightforward atm:
pipeline {
agent {
docker {
image 'maven:3-alpine'
args '-v /root/.m2:/root/.m2'
}
}
stages {
stage('Build') {
steps {
sh 'mvn -B -DskipTests clean install'
}
}
}
}
This produces the error "Could not create local repository at /var/empty/.m2/repository". If I specify a local repo in the command line I get the same error for whatever path I specified.
Jenkins is installed and running on a tomcat server, not in docker, which Jenkins mentions each time it runs, saying "Jenkins does not seem to be running inside a container".
The Jenkins console output looks like this:
[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 123:128 -v /root/.m2:/root/.m2 -w /usr/share/tomcat7/.jenkins/workspace/MyProject -v /usr/share/tomcat7/.jenkins/workspace/MyProject:/usr/share/tomcat7/.jenkins/workspace/MyProject:rw,z -v /usr/share/tomcat7/.jenkins/workspace/MyProject#tmp:/usr/share/tomcat7/.jenkins/workspace/MyProject#tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** maven:3-alpine cat
$ docker top 70c607bda0e397ed8ff79a183f33b2953ed94d82e4f36eb26dea87fa8c67adf3 -eo pid,comm
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] sh
[OMRS] Running shell script
+ mvn -B -DskipTests clean install
[ERROR] Could not create local repository at /var/empty/.m2/repository -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LocalRepositoryNotAccessibleException
Any help would be greatly appreciated. Thanks.
instead of mounting the root/.m2 folder to the container, you probably just need to run as root user:
pipeline {
agent {
docker {
image 'maven:3-alpine'
args '-u root'
}
}
stages {
stage('Build') {
steps {
sh 'mvn -B -DskipTests clean install'
}
}
}
}
To use current maven images in a jenkins pipeline as a non root user, try the following docker volume mapping and maven environment configuration:
args '-v $HOME/.m2:/var/maven/.m2:z -e MAVEN_CONFIG=/var/maven/.m2 -e MAVEN_OPTS="-Duser.home=/var/maven"'
https://github.com/carlossg/docker-maven#running-as-non-root