dockerjenkinsdockerfileargsjenkins-api

How can I pass parameters using jenkins-api into my Dockerfile


I am using the javascript jenkins-api to kick off a build via an express API as follows

jenkins.build_with_params('jobname', {param1: "xxxxxx", param2: "xxxxx"}, function(err, data) {
    if (err){

        console.log(err);
        res.json({success: false, msg: err});
    }
    else {
        console.log(data);
        res.json({success: true, msg: data});
    }

In this job I pull my code from github and then do

docker.build('myimage',' --build-arg param1=$param1 .',' --build-arg param2=$param2 .')

In my Dockerfile I have

ARG param1
ARG oaram2

I'm getting

hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: org.jenkinsci.plugins.docker.workflow.Docker.build() is applicable for argument types: (java.lang.String, java.lang.String java.lang.String) values: [myimage,  --build-arg param1=$param1 ., ...]

Solution

  • As per the doc the docker.build() takes two parameters 1st is docker image name and 2nd one is directory where dockerfile is present.

    The 2nd parameter can be extended by giving other parameters check below example.

    The last paramter should be the directory where dockerfile present or the working directory where your code is present.

    docker.build('myimage', '--build-arg param1=$param1 --build-arg param2=$param2 .')
    

    Add your build args in single string and add it as 2nd paramter.

    Hope this works.