Jenkins pipelines fail to use Jenkinsfile with 'agent {Dockerfile true }

Trying to get a docker image running with Jenkins pipelines for a couple of days now. I started out with Blue Ocean, but learned that this no longer works since the username/password stuff changed in github and bitbucket. My next approach was to ditch Blue Ocean all together, and just take the simplest example of Jenkins pipeline.

I created my jenkins job as follows:

  • new item in dashboard → pipeline → OK
  • pipeline definition => pipeline script from SCM
  • SCM = git
  • filled in my github branch
  • created credentials with username (NOT email address) and Personal Access Token (Full rights)
  • pointed to Jenkinsfile, which lives in the root of my main branch.

My initial Jenkinsfile works. It does nothing but echo something. Works fine.

Then the only change I made is change the Jenkinsfile to use a docker file:

agent { dockerfile true }

checked that in, and build again. Now it gives me the following error

The full Jenkinsfile for completeness:

pipeline {
    agent { dockerfile true }
    stages {
        stage('Test') {
            steps {
                echo 'bla'
            }
        }
    }
}

and the Dockerfile (although, it doesn’t even get that far, but just for reference)

FROM ubuntu

The both are in the root of my repository. Changing the line from
agent any
to
agent { dockerfile true }

causes the error:
Error response from daemon: Client sent an HTTP request to an HTTPS server.

I googled it, but I am getting nowhere. Can anybody help me getting further?

I think your jenkins <=> docker configuration isn’t quite right. The pipeline itself seems fine but its saying that the docker client (jenkins) is speaking http to the docker server, while its expecting https. I would recommend you look at /manage and see what your docker configuration is like.

I see a pretty big warning in my manage page:

Is that related? I don’t know what reverse proxies are really. For the rest I can’t find too much about http/https lookups. Is there anything more specific you could suggest to look at?

I am also running jenkins from its latest docker image. Starting it up as suggested by jenkins.io page. Followed the steps to the letter as suggested here. Is that red flag maybe?

Not really. Its saying the hostname your trying to access jenkins with, doesn’t match the hostname you have in your system configuration. Some things can break (more info will have more details).

Sadly I don’t use docker over http so I can’t really provide much details. It’ll have something todo with DOCKER_HOST env variable i think? hopefully someone else will know a little more. Feel free to screenshot your docker section of your jenkins config and we can see if we can spot something

Hello @qbpr and welcome to this community :wave:

Could you disable TLS by setting env var DOCKER_TLS_CERTDIR to “”?

DOCKER_TLS_CERTDIR=""

Hi @poddingue
sorry for the probably stupid question, but where do I add this?

1 Like

There is no such thing as a stupid question.
It is a environment variable, so you could add

export DOCKER_TLS_CERTDIR=""

before starting your container on your agent, or pass this variable on the command line:

docker run --name myAgent 
	-e DOCKER_TLS_CERTDIR="" \
        [...]
	yourJenkinsAgentImage

Oh oh oh oh… Found the problem.

I changed to much on my side. Started to understand better and better what I was doing (mostly was just copy pasting stuff from the tutorial, completely clueless of what I am doing). I now understand that I create a dind (docker in docker) container, which is used by the jenkins container. The are bound through a docker network, which I created twice with different names. They weren’t coupled…

So after wiping all I had in scripts, and just starting over, carefully changing what I needed to be changed this time, it works straight away…!

Thanks a lot for all the help here! Happy camper here!

1 Like