>
> We have reached acceptable solution for the problem. It is loading groovy 
> script with black magic around closure. Attaching code for the community 
> benefit.
>

It boils down to construct in the loaded groovy module:
def container(myImageName, Closure body){
    docker.image(myImageName).inside(dockerArgs(), body)
}


 And then using it passing closure body:
    def myImage = 'php:latest'
    def modelId = drun.modelId()

    echo modelId

    drun.container(myImage) {
        stage ('setup'){
            sh 'id'
            echo 'value = ' + modelId
        }

        stage('stage 1'){
            sh '/usr/local/bin/php -version'
        }
}

There is also custom step returning map of properties from the environment 
implemented as Java class:
public class DrunPropertiesStep extends Step {
...
    public static class Execution extends SynchronousStepExecution<Object> {
        private static final long serialVersionUID = 1;

        Execution(StepContext context) {
            super(context);
        }

        @Override
        protected Object run() throws Exception {
            Run run = getContext().get(Run.class);
            //todo: implement

            JSONObject json = Utils.getJson(run.getRootDir().getPath(), 
run.getLogReader());

            Map map = new HashMap<String, String>();
            Iterator iter = json.keys();
            while( iter.hasNext() ) {
                String key = iter.next().toString();

                map.put(key, json.getString(key));
            }

            return map;
        }
    }
...
}

Hope it will help to prevent someone from banging a head against the 
keyboard :)

Thanks
Alex

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/3cd3005a-9a64-48a4-b67b-2cae076d0e93%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: drun.groovy
Description: Binary data

Attachment: Jenkinsfile
Description: Binary data

Reply via email to