Help with groovy syntax

1,218 views
Skip to first unread message

kurr...@gmail.com

unread,
Feb 2, 2017, 7:06:25 PM2/2/17
to Jenkins Users
Hello

I had a jenkinsfile which worked perfectly, but after updating it no longer works.


Old Jenkinsfile
#!/usr/bin/groovy

def failIfNoTests = ""
try {
  failIfNoTests = ITEST_FAIL_IF_NO_TEST
} catch (Throwable e) {
  failIfNoTests = "false"
}

def itestPattern = ""
try {
  itestPattern = ITEST_PATTERN
} catch (Throwable e) {
  itestPattern = "*KT"
}

def versionPrefix = ""
try {
  versionPrefix = VERSION_PREFIX
} catch (Throwable e) {
  versionPrefix = "1.0"
}

def canaryVersion = "${versionPrefix}.${env.BUILD_NUMBER}"
//def utils = new io.fabric8.Utils()

node {
  def envProd = 'shiftwork-production'

  checkout scm




  kubernetes.pod('buildpod')
  .withNewContainer()
  .withImage('jhipster/jhipster')  
      .withPrivileged(true)
      .withHostPathMount('/var/run/docker.sock','/var/run/docker.sock')
      .withEnvVar('DOCKER_CONFIG','/home/jenkins/.docker/')
      .withSecret('jenkins-docker-cfg','/home/jenkins/.docker')
      .withSecret('jenkins-maven-settings','/root/.m2')
      .withServiceAccount('jenkins')
      .inside {
    stage 'Canary Release'
    mavenCanaryRelease{
      version = canaryVersion
    }

    stage 'Integration Test'
    mavenIntegrationTest{
      environment = 'Testing'
      failIfNoTests = localFailIfNoTests
      itestPattern = localItestPattern
    }

    stage 'Rolling Upgrade Production'
    def rc = readFile 'target/classes/kubernetes.json'
    kubernetesApply(file: rc, environment: envProd)

  }
}


New Syntax
So I'm trying to replace with the below groovy. But this results in an error. Im not familiar with groovy. The old DSL style syntax was very easy to read and write. The below, newer, syntax.
podTemplate(label: label, serviceAccount: 'jenkins', containers: [
         [name: 'maven', image: 'fabric8/maven-builder', command: 'cat', ttyEnabled: true, 
         envVars: [                
                 [key: 'DOCKER_CONFIG', value:'/home/jenkins/.docker/'],
                 ],
         [name: 'jnlp', image: 'iocanel/jenkins-jnlp-client:latest', command:'/usr/local/bin/start.sh', args: '${computer.jnlpmac} ${computer.name}', ttyEnabled: false,
                envVars: [
                 [key: 'DOCKER_HOST', value: 'unix:/var/run/docker.sock']
                 ]
                 ]
                 ],
         volumes: [
                [$class: 'PersistentVolumeClaim', mountPath: '/home/jenkins/.mvnrepository', claimName: 'jenkins-mvn-local-repo'],
                [$class: 'SecretVolume', mountPath: '/home/jenkins/.m2/', secretName: 'jenkins-maven-settings'],
                [$class: 'SecretVolume', mountPath: '/home/jenkins/.docker', secretName: 'jenkins-docker-cfg'],
                [$class: 'HostPathVolume', mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock']
        ]])

Error
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 34: Unexpected node type: EXPR found when expecting type: LABELED_ARG at line: 34 column: 10. File: WorkflowScript @ line 34, column 10.
           	[name: 'maven', image: 'fabric8/maven-builder', command: 'cat', ttyEnabled: true, 
            ^

Also, how do I write 
.withImage('jhipster/jhipster')
in the new syntax?

Thanks
Reply all
Reply to author
Forward
0 new messages