Jenkins does not run commands in docker agent - jenkins

I'm new in Jenkins and learning it right now.
I read that modern way to use Jenkins is to use docker containers as agents so:
I created jenkins image with docker installed
FROM jenkins/jenkins:lts
USER root
RUN apt-get update -qq && \
apt-get install -qqy apt-transport-https ca-certificates curl gnupg2 software-properties-common && \
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - && \
apt-key fingerprint 0EBFCD88 && \
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" && \
apt-get update -qq && \
apt-get install -qqy docker-ce && \
usermod -aG docker jenkins && \
chown -R jenkins:jenkins $JENKINS_HOME/
USER jenkins
Created docker-compose (instend running docker run command all the time)
version: '3.8'
services:
jenkins:
image: tmateusz/jenkins:lts
privileged: true
user: root
ports:
- 8080:8080
- 50000:50000
container_name: jenkins
volumes:
- /MY_PATH/jenkins_configuration:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
networks:
- jenkins
networks:
jenkins:
name: jenkins_network
Installed Docker Pipeline plugin in Jenkins Controller
Created really simple pipeline to check it works:
pipeline {
agent {
docker {
image 'eclipse-temurin:11'
}
}
stages {
stage('Check versions') {
steps {
sh 'java --version'
}
}
}
}
And it fails.
Checked again:
When I exec jenkins container (docker exec -it jenkins bash) - "docker ps" works (so docker is installed in Jenkins controller container)
When I run job - new container is created (with given image - image 'eclipse-temurin:11'
When i exec into this new agent container - java --version return expected results.
My job run and run (infinity - didnt wait more than 10 min)
Logs:
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 0:0 -w /var/jenkins_home/workspace/test-1.1 -v /var/jenkins_home/workspace/test-1.1:/var/jenkins_home/workspace/test-1.1:rw,z -v /var/jenkins_home/workspace/test-1.1#tmp:/var/jenkins_home/workspace/test-1.1#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 ******** eclipse-temurin:11 cat
$ docker top 6d738c52e04050b008d07e19ef4d917ae3350771e2e12d62db780c97879a25f7 -eo pid,comm
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Check versions)
[Pipeline] sh
Sending interrupt signal to process
Aborted by admin
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
$ docker stop --time=1 6d738c52e04050b008d07e19ef4d917ae3350771e2e12d62db780c97879a25f7
$ docker rm -f 6d738c52e04050b008d07e19ef4d917ae3350771e2e12d62db780c97879a25f7
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
It crash on running first Stage - I think that Jenkins agent container cant run pipeline commands.
How to do this? Is there something wrong with my Jenkins configuration?
Btw. working on linux

Related

Docker run - format issue - docker: invalid reference format

I hope this msg finds you well and healthy,
Im trying to run the commands bellow on Redhat 8
Docker version 20.10.3, build 48d30b5
and getting the error bellow, I'm not a Docker expert so not sure how to solve it, I appreciate your help,
docker run --rm \
-e INFLUXDB_DB=telegraf -e INFLUXDB_ADMIN_ENABLED=true \
-e INFLUXDB_ADMIN_USER=admin \ -e INFLUXDB_ADMIN_PASSWORD=secretpassss \
-e INFLUXDB_USER=telegraf -e INFLUXDB_USER_PASSWORD=secretpassss1 \
-v influxdb-volume:/var/lib/influxdb \
influxdb /init-influxdb.sh
Once copy past in terminal, Im getting an error
[root#dca monitoring]#
[root#dca monitoring]# docker run --rm \
> -e INFLUXDB_DB=telegraf -e INFLUXDB_ADMIN_ENABLED=true \
> -e INFLUXDB_ADMIN_USER=admin \ -e INFLUXDB_ADMIN_PASSWORD=secretpassss \
> -e INFLUXDB_USER=telegraf -e INFLUXDB_USER_PASSWORD=secretpassss1 \
> -v influxdb-volume:/var/lib/influxdb \
> influxdb /init-influxdb.sh
docker: invalid reference format.
See 'docker run --help'.
[root#dca monitoring]#

My jenkinsfile that uses a Docker agent hangs when being executed in Jenkins

I am running Jenkins 2.190.1 installed on a Linux Ubuntu LTD 18.04. I just tested the sample code in the Jenkins Guided Tour: https://jenkins.io/doc/pipeline/tour/hello-world/
In concrete my Jenkinsfile is as follows:
pipeline {
agent { docker { image 'maven:3.3.3' } }
stages {
stage('build') {
steps {
sh 'mvn --version'
}
}
}
}
This is the output that I receive in the jenkins console log:
$ docker run -t -d -u 122:127 -w /var/lib/jenkins/workspace/Tutorial -v /var/lib/jenkins/workspace/Tutorial:/var/lib/jenkins/workspace/Tutorial:rw,z -v /var/lib/jenkins/workspace/Tutorial#tmp:/var/lib/jenkins/workspace/Tutorial#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 ******** maven:3-alpine cat
$ docker top f7771c51c24b1a4d283f327c2ac26959f649f253778f53d65caa94edb0f35cfc -eo pid,comm
[Pipeline] {
[Pipeline] sh
process apparently never started in /var/lib/jenkins/workspace/Tutorial#tmp/durable-74c26f6c
(running Jenkins temporarily with -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true might make the problem clearer)
[Pipeline] }
$ docker stop --time=1 f7771c51c24b1a4d283f327c2ac26959f649f253778f53d65caa94edb0f35cfc
$ docker rm -f f7771c51c24b1a4d283f327c2ac26959f649f253778f53d65caa94edb0f35cfc
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
ERROR: script returned exit code -2
Finished: FAILURE

Running Dell Boomi atom on Docker

I retrieved the most recent image using docker pull boomi/atom:2.3.0
I then run the following script (using placeholders for USERNAME, PASSWORD and ACCOUNT_ID):
#!/bin/bash
atom_name=boomidemo01
docker stop $atom_name
docker rm $atom_name
docker run -p 9090:9090 -h boomidemo01 -e URL="platform.boomi.com" \
-e BOOMI_USERNAME=<USERNAME> -e BOOMI_PASSWORD=<PASSWORD> \
-e BOOMI_ATOMNAME=$atom_name \
-e BOOMI_CONTAINERNAME=$atom_name \
-e BOOMI_ACCOUNTID=<ACCOUNT_ID> \
--name $atom_name \
-d -t boomi/atom:2.3.0
But the atom fails to start (not able to connect on port 9090 via a browser on http://127.0.0.1:9090). Did anyone managed to use docker for running a Boomi atom?
I eventually figured it out... the following script works
#!/bin/bash
atom_name=boomidemo01
host_dir=/home/user/Boomi
docker stop $atom_name
docker rm $atom_name
docker run -p 9090:9090 -h $atom_name \
-v $host_dir:/home/boomi/host_dir \
-e URL=https://platform.boomi.com \
-e BOOMI_USERNAME=<USERNAME> \
-e BOOMI_PASSWORD=<PASSWORD> \
-e BOOMI_ATOMNAME=$atom_name \
-e BOOMI_CONTAINERNAME=$atom_name \
-e BOOMI_ACCOUNTID=<ACCOUNT_ID> \
-e PROXY_HOST= \
-e PROXY_USERNAME= \
-e PROXY_PASSWORD= \
-e PROXY_PORT= \
-e DOCKERUID= \
-e SYMLINKS_DIR= \
-e ATOM_LOCALHOSTID=$atom_name \
-e INSTALL_TOKEN= \
--name $atom_name \
-d -t boomi/atom:2.3.0
Download the docker install script from within the UI.
Generate the token.
Run the script with the name, and token.
The port does not matter because Atomsphere is never pinged. It fetches processes for you.

Jenkins declarative pipeline docker agent: Timeout run

I'm trying to improve my build times for my Jenkins jobs and am trying to build docker containers with my dependencies preinstalled.
I have the following (partial) Jenkinsfile:
pipeline {
agent {
docker {
image 'docker-local.artifactory.com/app-chromium:latest'
registryUrl 'https://docker-local.artifactory.com/'
registryCredentialsId 'artifactoryapikey'
}
}
}
And, according to the logs, jenkins is properly downloading this image. The problem occurs when it tries to run it:
[Pipeline] withDockerContainer
swarm-sjc01-0270eda05830-0.0.0.0 seems to be running inside container 0270eda05830a074668a5864c52d153377eb67b6406e3912b99f79686cfaca1c
but /home/jenkins/workspace/app_PR-6011-N3O6YOXQAC4KEFHSOKKCS7CFV3GUTIIJAVHDJCR5T7LMXUPU3SLQ could not be found among []
but /home/jenkins/workspace/app_PR-6011-N3O6YOXQAC4KEFHSOKKCS7CFV3GUTIIJAVHDJCR5T7LMXUPU3SLQ#tmp could not be found among []
$ docker run -t -d -u 1000:1000 -w /home/jenkins/workspace/app_PR-6011-N3O6YOXQAC4KEFHSOKKCS7CFV3GUTIIJAVHDJCR5T7LMXUPU3SLQ -v /home/jenkins/workspace/app_PR-6011-N3O6YOXQAC4KEFHSOKKCS7CFV3GUTIIJAVHDJCR5T7LMXUPU3SLQ:/home/jenkins/workspace/app_PR-6011-N3O6YOXQAC4KEFHSOKKCS7CFV3GUTIIJAVHDJCR5T7LMXUPU3SLQ:rw -v /home/jenkins/workspace/app_PR-6011-N3O6YOXQAC4KEFHSOKKCS7CFV3GUTIIJAVHDJCR5T7LMXUPU3SLQ#tmp:/home/jenkins/workspace/app_PR-6011-N3O6YOXQAC4KEFHSOKKCS7CFV3GUTIIJAVHDJCR5T7LMXUPU3SLQ#tmp:rw -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 ******** --entrypoint cat icm-docker-local.artifactory.swg-devops.com/app-chromium:latest
ERROR: Timeout after 10 seconds
[Pipeline] // withDockerContainer
Does anyone understand why it times out? If i provide a dockerfile instead (agent { dockerfile: true }) it builds fine. Not that this is not using the script like pipeline syntax but the newer declarative format.

Multi-host Validating Peer Cluster Setup

I am attempting to create a cluster of Hyperledger validating peers, each running on a different host, but it does not appear to be functioning properly.
After starting the root node and 3 peer nodes, this is the output running peer network list on the root node, vp0:
{"peers":[{"ID":{"name":"vp1"},"address":"172.17.0.2:30303","type":1},{"ID":{"name":"vp2"},"address":"172.17.0.2:30303","type":1},{"ID":{"name":"vp3"},"address":"172.17.0.2:30303","type":1}]}
This is the output from the same command on one of the peers, vp3:
{"peers":[{"ID":{"name":"vp0"},"address":"172.17.0.2:30303","type":1},{"ID":{"name":"vp3"},"address":"172.17.0.2:30303","type":1}]}
All of the peers only list themselves and the root, vp0, in their lists.
This is the log output from the root node, vp0: https://gist.github.com/mikezaccardo/f139eaf8004540cdfd24da5a892716cc
This is the log output from one of the peer nodes, vp3: https://gist.github.com/mikezaccardo/7379584ca4f67bce553c288541e3c58e
This is the command I'm running to create the root node:
nohup sudo docker run --name=$HYPERLEDGER_PEER_ID \
--restart=unless-stopped \
-i \
-p 5000:5000 \
-p 30303:30303 \
-p 30304:30304 \
-p 31315:31315 \
-e CORE_VM_ENDPOINT=http://172.17.0.1:4243 \
-e CORE_PEER_ID=$HYPERLEDGER_PEER_ID \
-e CORE_PEER_ADDRESSAUTODETECT=true \
-e CORE_PEER_NETWORKID=dev \
-e CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft \
-e CORE_PBFT_GENERAL_MODE=classic \
-e CORE_PBFT_GENERAL_N=$HYPERLEDGER_CLUSTER_SIZE \
-e CORE_PBFT_GENERAL_TIMEOUT_REQUEST=10s \
joequant/hyperledger /bin/bash -c "rm config.yaml; cp /usr/share/go-1.6/src/github.com/hyperledger/fabric/consensus/obcpbft/config.yaml .; peer node start" > $HYPERLEDGER_PEER_ID.log 2>&1&
And this is the command I'm running to create each of the other peer nodes:
nohup sudo docker run --name=$HYPERLEDGER_PEER_ID \
--restart=unless-stopped \
-i \
-p 30303:30303 \
-p 30304:30304 \
-p 31315:31315 \
-e CORE_VM_ENDPOINT=http://172.17.0.1:4243 \
-e CORE_PEER_ID=$HYPERLEDGER_PEER_ID \
-e CORE_PEER_DISCOVERY_ROOTNODE=$HYPERLEDGER_ROOT_NODE_ADDRESS:30303 \
-e CORE_PEER_ADDRESSAUTODETECT=true \
-e CORE_PEER_NETWORKID=dev \
-e CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft \
-e CORE_PBFT_GENERAL_MODE=classic \
-e CORE_PBFT_GENERAL_N=$HYPERLEDGER_CLUSTER_SIZE \
-e CORE_PBFT_GENERAL_TIMEOUT_REQUEST=10s \
joequant/hyperledger /bin/bash -c "rm config.yaml; cp /usr/share/go-1.6/src/github.com/hyperledger/fabric/consensus/obcpbft/config.yaml .; peer node start" > $HYPERLEDGER_PEER_ID.log 2>&1&
HYPERLEDGER_PEER_ID is vp0 for the root node and vp1, vp2, ... for the peer nodes, HYPERLEDGER_ROOT_NODE_ADDRESS is the public IP address of the root node, and HYPERLEDGER_CLUSTER_SIZE is 4.
This is the Docker image that I am using: github.com/joequant/hyperledger
Is there anything obviously wrong with my commands? Should the actual public IP addresses of the peers be showing up as opposed to just 172.17.0.2? Are my logs helpful / is any additional information needed?
Any help or insight would be greatly appreciated, thanks!
I've managed to get a noops cluster working in which all nodes discover each other and chaincodes successfully deploy.
I made a few fixes since my post above:
I now use mikezaccardo/hyperledger-peer image, a fork of yeasy/hyperledger-peer, instead of joequant/hyperledger.
I changed:
-e CORE_PEER_ADDRESSAUTODETECT=true \
to:
-e CORE_PEER_ADDRESS=$HOST_ADDRESS:30303 \
-e CORE_PEER_ADDRESSAUTODETECT=false \
so that each peer would advertise its public IP, not private.
And I properly tag my image as the official base image:
sudo docker tag mikezaccardo/hyperledger:latest hyperledger/fabric-baseimage:latest
Finally, for context, this is all related to my development of a blueprint for Apache Brooklyn which deploys a Hyperledger Fabric cluster. That repository, which contains all of the code mentioned in this post and answer, can be found here: https://github.com/cloudsoft/brooklyn-hyperledger.

Resources