The example given on https://github.com/jenkinsci/kubernetes-pipeline-plugin/blob/master/kubernetes-steps/readme.md (see below) is incorrect and results in an error.

      kubernetes.pod('buildpod')
          .withNewContainer().withName(<name1>).withImage(<image1>)
                             .withEnv(<key1>,<value1>) //incorrect
                             .withSecret(<mount path>, <secret name>)  //incorrect
                             .and()
          .withNewContainer().withName(<name2>).withImage(<image2>).inside {                       
              sh '<some shell commands that are going to be run inside name2>'
      }
      

      Error

      hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: static io.fabric8.kubernetes.pipeline.Kubernetes.withEnv() is applicable for argument types: (java.lang.String, java.lang.String) 
      

      More info is on https://github.com/fabric8io/fabric8-pipeline-library/issues/69

          [JENKINS-41702] Example on github is incorrect

          Anton Hughes added a comment - - edited

          Am I correct in thinking that it should be something like the following:

          List<EnvVar> envVars = container.getEnv();
                      envVars.add(new EnvVarBuilder().withName("KUBERNETES_MASTER_URI").withValue("k8s").build());
          

          Then

          kubernetes.pod('buildpod')
            .withNewContainer()
            	.withImage('jhipster/jhipster')  	
                .withPrivileged(true)
                //.withHostPathMount('/var/run/docker.sock','/var/run/docker.sock')
                .withEnv(envVars)
                .withSecret('jenkins-docker-cfg','/home/jenkins/.docker')
                .withSecret('jenkins-maven-settings','/root/.m2')
                .withServiceAccount('jenkins')
          

          This unfortunately fails to compile:

          org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
          WorkflowScript: 33: unable to resolve class EnvVar 
           @ line 33, column 8.
               List<EnvVar> envVars = container.getEnv();
                    ^
          
          WorkflowScript: 34: unable to resolve class EnvVarBuilder 
           @ line 34, column 25.
                         envVars.add(new EnvVarBuilder().withName("DOCKER_CONFIG").withValue("/home/jenkins/.docker/").build());
                                     ^
          
          2 errors
          

          Anton Hughes added a comment - - edited Am I correct in thinking that it should be something like the following: List<EnvVar> envVars = container.getEnv(); envVars.add( new EnvVarBuilder().withName( "KUBERNETES_MASTER_URI" ).withValue( "k8s" ).build()); Then kubernetes.pod( 'buildpod' ) .withNewContainer() .withImage( 'jhipster/jhipster' ) .withPrivileged( true ) //.withHostPathMount( '/ var /run/docker.sock' , '/ var /run/docker.sock' ) .withEnv(envVars) .withSecret( 'jenkins-docker-cfg' , '/home/jenkins/.docker' ) .withSecret( 'jenkins-maven-settings' , '/root/.m2' ) .withServiceAccount( 'jenkins' ) This unfortunately fails to compile: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 33: unable to resolve class EnvVar @ line 33, column 8. List<EnvVar> envVars = container.getEnv(); ^ WorkflowScript: 34: unable to resolve class EnvVarBuilder @ line 34, column 25. envVars.add(new EnvVarBuilder().withName("DOCKER_CONFIG").withValue("/home/jenkins/.docker/").build()); ^ 2 errors

          what should work is:

          .withEnvar(key, value)

          Ioannis Canellos added a comment - what should work is: .withEnvar(key, value)

          Anton Hughes added a comment -

          Ok, that worked.

          Now we have a problem with the next method:

          hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: static io.fabric8.kubernetes.pipeline.Kubernetes.withSecret() is applicable for argument types: (java.lang.String, java.lang.String) values: [jenkins-docker-cfg, /home/jenkins/.docker]
          

          Anton Hughes added a comment - Ok, that worked. Now we have a problem with the next method: hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: static io.fabric8.kubernetes.pipeline.Kubernetes.withSecret() is applicable for argument types: (java.lang. String , java.lang. String ) values: [jenkins-docker-cfg, /home/jenkins/.docker]

          Anton Hughes added a comment - - edited

          And also

          io.fabric8.kubernetes.pipeline.Kubernetes.withServiceAccount() 
          is applicable for argument types: (java.lang.String) values: [jenkins]
          

          Anton Hughes added a comment - - edited And also io.fabric8.kubernetes.pipeline.Kubernetes.withServiceAccount() is applicable for argument types: (java.lang.String) values: [jenkins]

          While developing the kubernetes-pipeline-plugin, it started made more sense if the pipeline functionality was directly provided by the kubernetes-plugin.

          Thus, we focused there and never even released kubernetes-pipeline-plugin officially.

          I have tried to align the two plugins, but currently I don't have the cycles to do so.

          Maybe if it makes sense we could pickup the DSL part to kubernetes-plugin. csanchez wdyt?

          Ioannis Canellos added a comment - While developing the kubernetes-pipeline-plugin, it started made more sense if the pipeline functionality was directly provided by the kubernetes-plugin. Thus, we focused there and never even released kubernetes-pipeline-plugin officially. I have tried to align the two plugins, but currently I don't have the cycles to do so. Maybe if it makes sense we could pickup the DSL part to kubernetes-plugin. csanchez wdyt?

          Anton Hughes added a comment - - edited

          While developing the kubernetes-pipeline-plugin, it started made more sense if the pipeline functionality was directly provided by the kubernetes-plugin.

          This wouldnt make sense for us, at least not now. We have just 2 more methods to get working then we can - hopefully - get operational again, after being unable to deploy our apps for weeks.

          The new syntax is completely different, and it would be a massive undertaking for us to migrate.

          For now it makes sense for us to just get working again with what used to work, and not have to spend time learning a new syntax for something that is still under development.

          So if you can just help use to get the following working, we would be supremely appreciative!

          .withSecret('jenkins-maven-settings','/root/.m2')
          .withServiceAccount('jenkins')
          

          Anton Hughes added a comment - - edited While developing the kubernetes-pipeline-plugin, it started made more sense if the pipeline functionality was directly provided by the kubernetes-plugin. This wouldnt make sense for us, at least not now. We have just 2 more methods to get working then we can - hopefully - get operational again, after being unable to deploy our apps for weeks. The new syntax is completely different, and it would be a massive undertaking for us to migrate. For now it makes sense for us to just get working again with what used to work, and not have to spend time learning a new syntax for something that is still under development. So if you can just help use to get the following working, we would be supremely appreciative! .withSecret( 'jenkins-maven-settings' , '/root/.m2' ) .withServiceAccount( 'jenkins' )

          These methods are expected to work as they always should (in the pod level). So try it like:

          kubernetes.pod('buildpod')
          .withSecret('jenkins-docker-cfg','/home/jenkins/.docker')
          .withSecret('jenkins-maven-settings','/root/.m2')
          .withServiceAccount('jenkins')
          .withNewContainer()
          .withImage('jhipster/jhipster')
          .withPrivileged(true)
          //.withHostPathMount('/var/run/docker.sock','/var/run/docker.sock')
          .withEnv(envVars)

          Ioannis Canellos added a comment - These methods are expected to work as they always should (in the pod level). So try it like: kubernetes.pod('buildpod') .withSecret('jenkins-docker-cfg','/home/jenkins/.docker') .withSecret('jenkins-maven-settings','/root/.m2') .withServiceAccount('jenkins') .withNewContainer() .withImage('jhipster/jhipster') .withPrivileged(true) //.withHostPathMount('/var/run/docker.sock','/var/run/docker.sock') .withEnv(envVars)

          Anton Hughes added a comment - - edited

          You wrote:

          .withEnv(envVars)
          

          Is this correct?
          If yes, how to construct the input variable?

          Anton Hughes added a comment - - edited You wrote: .withEnv(envVars) Is this correct? If yes, how to construct the input variable?

            iocanel Ioannis Canellos
            anton93 Anton Hughes
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: