Using agent dockerfile AND label in a declarative pipeline

1.563 προβολές
Παράβλεψη και μετάβαση στο πρώτο μη αναγνωσμένο μήνυμα

Damien Coraboeuf

μη αναγνωσμένη,
15 Φεβ 2017, 3:30:16 μ.μ.15/2/17
ως Jenkins Users
Hi,

I'm starting to migrate some projects to the declarative pipeline model. In particular, we want to build on an agent designated by the "docker" label (which runs a Docker daemon) and then, I want to build inside a Docker container described by my Dockerfile.

Doing this:

pipeline {
   agent
{
     label
"docker"
     dockerfile
true
   
}
}

This generates an error:

Only one agent type is allowed per agent section

Now, what should be the best approach to solve this, I think, common pattern?

I will try using agent+label, and then using docker+build+inside in steps, but would not it more elegant to allow to use both a label and a Dockerfile in the agent declaration?

Thanks you for any feedback,
Damien.

Damien Coraboeuf

μη αναγνωσμένη,
16 Φεβ 2017, 5:30:18 π.μ.16/2/17
ως Jenkins Users
Done after having looked at https://github.com/jenkinsci/pipeline-model-definition-plugin/wiki/Syntax-Reference :)

So, this now works:

pipeline {

    agent {
        dockerfile {
            label "docker"
        }
    }

    // ...
}

In order to restrict the data sent to the Docker daemon, I also declare a .dockerignore file which contains only:

*
!Dockerfile

This way, only the Dockerfile itself is sent to the build context for the image.

Best regards,
Damien.
Απάντηση σε όλους
Απάντηση στον συντάκτη
Προώθηση
0 νέα μηνύματα