How does the Jenkins CloudBees Docker Build Plugin set its Shell Path - docker

I'm working with a Jenkins install I've inherited. This install has the CloudBees Docker Custom Build Environment Plugin installed. We think this plugin gives us a nifty Build inside a Docker container checkbox in our build configuration. When we configure jobs with this option, it looks like (based on Jenkins console output) Jenkins runs the build with the following command
Docker container 548ab230991a452af639deed5eccb304026105804b38194d98250583bd7bb83q started to host the build
[WIP-Tests] $ docker exec -t 548ab230991a452af639deed5eccb304026105804b38194d98250583bd7bb83q /bin/sh -xe /tmp/hudson7939624860798651072.sh
However -- we've found that this runs /bin/sh with a very limited set of environmental variables -- including a $PATH that doesn't include /bin! So
How does the CloudBees Docker Custom Build Environment Plugin setup its /bin/sh environment. Is this user configurable via the UI (if so, where?)
It looks like Jenkins is using docker exec -- which i think means that it must have (invisibly) setup a container with a long running process using docker run. Doesn't anyone know how the CloudBees Docker Custom Build Environment Plugin plugin invokes docker run, and if this is user manageable?

Considering this plugin is "up for adoption", I would recommend the official JENKINS/Docker Pipeline Plugin.
It source code show very few recent commits.
But don't forget any container has a default entrypoint set to /bin/sh
ENTRYPOINT ["/bin/sh", "-c"]
Then:
The docker container is ran after SCM has been checked-out into a slave workspace, then all later build commands are executed within the container thanks to docker exec introduced in Docker 1.3
That means the image you will be pulling or building/running must have a shell, to allow the docker exec to execute a command in it.

Related

how to run docker build command in jenkins shell prompt

I want to run docker build command in Jenkins shell prompt.
Have already installed docker and add Jenkins user in docker usergroup.
But when i hit docker build command it shows me permission denied issue and when i am using sudo prefix it ask for password with -S argument.
I am running all commands on Jenkins master, earlier i used on other node server not master.
So what is best way to resolve this.

How create a freestyle jenkins job which is running in docker

I have a simple c++ to compile and run using jenkins freestyle job it is working fine if I use jenkins built in my OS (Linux mint tricia) commands I use:
cd "destination"
g++ main.cpp -o test
./test
everything is working good.
BUT,now I m running jenkins from docker container and when I try to do this I get error cant cd to "destination", I know this is because docker is isolated from host machine, So I want to ask how could I make a simple freestyle job which executes programs which is on my host machine using jenkins which is running inside docker?
Thank You
Just run your jenknis container with volume like docker run -it -v destination:destination jenkins

Run a script inside docker container using octopus deploy

Trying to do config transformation once a docker container has been created and the docker CP command does not allow wildcard and file type searches. While testing manually, it was found that it was possible to solve this issue but running the docker exec command and running powershell inside our container. After some preliminary tests it doesn't look like this works out of the box with octopus deploy. Is there a way to run process steps inside a container with octopus deploy?
Turns out you can run powershell scripts that already exist in the container with the exec command:
docker exec <container> powershell script.ps1 -argument foo
This command will run a script as you would expect in command line.

Run `bash` command on Jenkins in windows hang forever

I am running Jenkins job on a windows10 machine. And I have installed ubuntu shell on the windows. The Jenkins job works fine with windows batch commands. But it stuck there when I try to run bash command. For example, I created an Execute Windows batch command build step, if I put command bash -c ls, this command never finishes.
It works fine if I run the same command in the windows directly.
How can I configure Jenkins job to work with bash command?
Below is the build step configuration. There are two commands. The first one is used to install dependencies on my nodejs application. The second command is used to run a command in bash shell. The problem is that the build is stuck on the second command.
Have you made any Global configurations in jenkins. try giving the command with the home path of Ubuntu shell and re run the command once.

How to get Container Id of Docker in Jenkins

I am using Docker Custom Build Environment Plugin to build my project inside "jpetazzo/dind" docker image. After building, in console output it shows:
Docker container 212ad049dfdf8b7180b8c9b185ddfc586b301174414c40969994f7b3e64f68bc started to host the build
$ docker exec --tty 212ad049dfdf8b7180b8c9b185ddfc586b301174414c40969994f7b3e64f68bc env
[workspace] $ docker exec --tty --user 122:docker 4aea29fff86ba4e50dbcc7387f4f23c55ff3661322fb430a099435e905d6eeef env BUILD_DISPLAY_NAME=#73
Here Docker Container which got started has container id 212ad049dfdf8b7180b8c9b185ddfc586b301174414c40969994f7b3e64f68bc .
Now further I want to execute some command on "Execute shell" part in "Build" option in Jenkins, there I want to use this Container Id. I tried using ${BUILD_CONTAINER_ID} as mentioned in the plugin page. But that does't work.
The documentation tells you to use docker run, but you're trying to do docker exec. The exec subcommand only works on a currently running container.
I suppose you could do a docker run -d to start the container in the background, and then make sure to docker stop when you're done. I suspect this will leave you with some orphaned running containers when things go wrong, though.

Resources