params is null

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

params is null

David Harvey
Hi,

I'm experiencing a strange issue with a specific build in Jenkins where params is returning a null pointer exception. The Jenkinsfile being used is:

#!groovy

def paramsVar = []
def rebuild = [$class: 'RebuildSettings', autoRebuild: true, rebuildDisabled: false]

if (env.BRANCH_NAME == 'master') {
    paramsVar
<< choice(name: 'ENVIRONMENT', choices: ['int', 'iuat', 'iprod']) <<
                 choice
(name: 'REGION', choices: ['us-east-1','eu-west-1'])

    rebuild
<< [$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: true]
}

properties
(
   
[rebuild,
      parameters
(
        paramsVar
     
)
   
]
 
)

pipeline
{
    agent
{
            dockerfile
{
                label
"env-${params.ENVIRONMENT} && ${params.REGION}"
                filename
'Dockerfile.agent'
                args
'-v /var/run/docker.sock:/var/run/docker.sock  --group-add 497'
           
}
       
}

    environment
{
        ENVIRONMENT_NAME
= "${params.ENVIRONMENT}"
        REGION
= "${params.REGION}"

        MYSQL_KAFKA_CONNECT_CREDENTIALS  
= credentials("l48-mysql-kafka-connect-credentials-${ENVIRONMENT_NAME}")
        MYSQL_REVIEW_CREDENTIALS          
= credentials("l48-mysql-review-credentials-${ENVIRONMENT_NAME}")
        MYSQL_HOST                        
= credentials("l48-mysql-host-${ENVIRONMENT_NAME}")
        MYSQL_DATABASE                    
= 'review'

        KAFKA_CONNECT_BASE_URL            
= credentials("l48-kafka-connect-base-url-${ENVIRONMENT_NAME}")

        ELASTICSEARCH_MONITORING_BASE_URL
= credentials("l48-es-monitoring-base-url-${ENVIRONMENT_NAME}")
        ELASTICSEARCH_DOMAIN_BASE_URL    
= credentials("l48-es-domain-base-url-${ENVIRONMENT_NAME}")
        ELASTICSEARCH_MONITORING          
= 'elasticMonitoring'
        ELASTICSEARCH_DOMAIN              
= 'elasticDomain'
   
}

    stages
{
        stage
('Prepare build environment') {
            steps
{
                    script
{
                    currentBuild
.displayName = "#${BUILD_NUMBER} ${ENVIRONMENT_NAME}@${REGION}"
                    currentBuild
.description = "#${BUILD_NUMBER} ${ENVIRONMENT_NAME}@${REGION}"
               
}
           
}
       
}

        stage
('Deploy ES Monitoring Indexes') {
            steps
{
                sh
'./elasticsearch.sh ${ELASTICSEARCH_MONITORING} ${ELASTICSEARCH_MONITORING_BASE_URL}'
           
}
       
}

        stage
('Deploy ES Domain Indexes') {
            steps
{
                sh
'./elasticsearch.sh ${ELASTICSEARCH_DOMAIN} ${ELASTICSEARCH_DOMAIN_BASE_URL}'
             
}
       
}

        stage
('Deploy MySQL Schemas') {
            steps
{
               sh
'./mysql.sh ${MYSQL_HOST} ${MYSQL_REVIEW_CREDENTIALS_USR} ${MYSQL_REVIEW_CREDENTIALS_PSW} ${MYSQL_DATABASE}'
           
}
       
}

        stage
('Deploy Kafka Connect Connectors') {
            steps
{
                sh
'./kafka-connect.sh ${KAFKA_CONNECT_BASE_URL} "jdbc:mysql://${MYSQL_HOST}:3306/${MYSQL_DATABASE}?user=${MYSQL_KAFKA_CONNECT_CREDENTIALS_USR}&password=${MYSQL_KAFKA_CONNECT_CREDENTIALS_PSW}&useSSL=false"'
           
}
       
}

        stage
('Check Kafka Connect Connectors Status') {
            steps
{
                sh
'./kafka-connect-status.sh ${KAFKA_CONNECT_BASE_URL}'
           
}
       
}
   
}
}

I've also tried with the more straightforward:
pipeline {
   agent {
           dockerfile {
               label "env-${params.ENVIRONMENT} && ${params.REGION}"
               filename 'Dockerfile.agent'
               args '-v /var/run/docker.sock:/var/run/docker.sock  --group-add 497'
           }
       }

    parameters {
       choice(
           name: 'ENVIRONMENT',
           choices: ['int', 'iuat', 'iprod'],
           description: 'Environment to deploy to.'
       )

        choice(
           name: 'REGION',
           choices: ['us-east-1', 'eu-west-1'],
           description: 'Region to deploy to.'
       )
   }

    environment {
       ENVIRONMENT_NAME = "${params.ENVIRONMENT}"
       REGION = "${params.REGION}"

        MYSQL_KAFKA_CONNECT_CREDENTIALS   = credentials("l48-mysql-kafka-connect-credentials-${ENVIRONMENT_NAME}")
       MYSQL_REVIEW_CREDENTIALS          = credentials("l48-mysql-review-credentials-${ENVIRONMENT_NAME}")
       MYSQL_HOST                        = credentials("l48-mysql-host-${ENVIRONMENT_NAME}")
       MYSQL_DATABASE                    = 'review'

        KAFKA_CONNECT_BASE_URL            = credentials("l48-kafka-connect-base-url-${ENVIRONMENT_NAME}")

        ELASTICSEARCH_MONITORING_BASE_URL = credentials("l48-es-monitoring-base-url-${ENVIRONMENT_NAME}")
       ELASTICSEARCH_DOMAIN_BASE_URL     = credentials("l48-es-domain-base-url-${ENVIRONMENT_NAME}")
       ELASTICSEARCH_MONITORING          = 'elasticMonitoring'
       ELASTICSEARCH_DOMAIN              = 'elasticDomain'
       MYSQL                             = 'mysql'
   }

    stages {
       stage('Prepare build environment') {
           steps {
                   script {
                   currentBuild.displayName = "#${BUILD_NUMBER} ${ENVIRONMENT_NAME}@${REGION}"
                   currentBuild.description = "#${BUILD_NUMBER} ${ENVIRONMENT_NAME}@${REGION}"
               }
           }
       }

        stage('Deploy ES Monitoring Indexes') {
           steps {
               sh './elasticsearch.sh ${ELASTICSEARCH_MONITORING} ${ELASTICSEARCH_MONITORING_BASE_URL}'
           }
       }

        stage('Deploy ES Domain Indexes') {
           steps {
               sh './elasticsearch.sh ${ELASTICSEARCH_DOMAIN} ${ELASTICSEARCH_DOMAIN_BASE_URL}'
            }
       }

        stage('Deploy MySQL Schemas') {
           steps {
              sh './mysql.sh ${MYSQL_HOST} ${MYSQL_REVIEW_CREDENTIALS_USR} ${MYSQL_REVIEW_CREDENTIALS_PSW} ${MYSQL_DATABASE}'
           }
       }

        stage('Deploy Kafka Connect Connectors - MySQL') {
           steps {
               sh './kafka-connect.sh ${KAFKA_CONNECT_BASE_URL} ${MYSQL} "jdbc:mysql://${MYSQL_HOST}:3306/${MYSQL_DATABASE}?user=${MYSQL_KAFKA_CONNECT_CREDENTIALS_USR}&password=${MYSQL_KAFKA_CONNECT_CREDENTIALS_PSW}&useSSL=false"'
           }
       }

        stage('Deploy Kafka Connect Connectors - Elasticsearch Monitoring') {
           steps {
               sh './kafka-connect.sh ${KAFKA_CONNECT_BASE_URL} ${ELASTICSEARCH_MONITORING} ${ELASTICSEARCH_MONITORING_BASE_URL}'
           }
       }

        stage('Deploy Kafka Connect Connectors - Elasticsearch Domain') {
           steps {
               sh './kafka-connect.sh ${KAFKA_CONNECT_BASE_URL} ${ELASTICSEARCH_DOMAIN} ${ELASTICSEARCH_DOMAIN_BASE_URL}'
           }
       }

        stage('Check Kafka Connect Connectors Status') {
           steps {
               sh './kafka-connect-status.sh ${KAFKA_CONNECT_BASE_URL}'
           }
       }
   }
}

The error being generated is:

java.lang.NullPointerException: Cannot get property 'params' on null object
        at org
.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:60)
        at sun
.reflect.GeneratedMethodAccessor771.invoke(Unknown Source)
        at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java
.lang.reflect.Method.invoke(Method.java:498)
        at org
.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
        at groovy
.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at groovy
.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
        at groovy
.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
        at org
.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
        at org
.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at org
.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:35)
        at org
.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at org
.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:57)
        at org
.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
        at org
.jenkinsci.plugins.pipeline.modeldefinition.Utils.getScriptPropOrParam(Utils.groovy:116)
        at org
.jenkinsci.plugins.pipeline.modeldefinition.Utils$getScriptPropOrParam$17.call(Unknown Source)
        at org
.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at org
.jenkinsci.plugins.pipeline.modeldefinition.Utils$getScriptPropOrParam$17.call(Unknown Source)
        at org
.jenkinsci.plugins.pipeline.modeldefinition.model.Environment$EnvironmentResolver.getScriptPropOrParam(Environment.groovy:133)
        at sun
.reflect.GeneratedMethodAccessor8320.invoke(Unknown Source)
        at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java
.lang.reflect.Method.invoke(Method.java:498)
        at org
.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
        at groovy
.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at groovy
.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
        at groovy
.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
        at org
.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
        at org
.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at org
.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
        at org
.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:158)
        at org
.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
        at org
.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:157)
        at org
.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:156)
        at org
.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:160)
        at org
.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:125)
        at org
.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:130)
        at com
.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
        at
WorkflowScript.run(WorkflowScript)
        at
WorkflowScript.run(WorkflowScript)
        at
WorkflowScript.run(WorkflowScript)
        at
WorkflowScript.run(WorkflowScript)
        at org
.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withCredentialsBlock(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:484)
        at com
.cloudbees.groovy.cps.CpsDefaultGroovyMethods.callClosureForMapEntry(CpsDefaultGroovyMethods:5226)
        at com
.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2107)
        at org
.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withCredentialsBlock(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:483)
        at org
.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.call(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:77)
        at org
.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.inDeclarativeAgent(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:611)
        at org
.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.DockerPipelineFromDockerfileScript.runImage(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/DockerPipelineFromDockerfileScript.groovy:57)
        at org
.jenkinsci.plugins.docker.workflow.Docker$Image.inside(jar:file:/var/jenkins_home/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:135)
        at ___cps
.transform___(Native Method)
        at com
.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
        at com
.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
        at com
.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
        at sun
.reflect.GeneratedMethodAccessor681.invoke(Unknown Source)
        at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java
.lang.reflect.Method.invoke(Method.java:498)
        at com
.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
        at com
.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
        at com
.cloudbees.groovy.cps.Next.step(Next.java:83)
        at com
.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
        at com
.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
        at org
.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
        at org
.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
        at com
.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
        at org
.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
        at org
.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
        at org
.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
        at org
.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:347)
        at org
.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:93)
        at org
.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:259)
        at org
.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:247)
        at org
.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
        at java
.util.concurrent.FutureTask.run(FutureTask.java:266)
        at hudson
.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
        at jenkins
.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
        at jenkins
.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
        at java
.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java
.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java
.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java
.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java
.lang.Thread.run(Thread.java:748)


I've tried recreating the job within Jenkins but still get the same error.

Does anyone have any pointers on what could be going wrong?

Other jobs using parameters from both Jenkinsfile methods are working with no issues.

Thanks,

David

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/4a4a0a3f-997c-463b-85ab-fdc8fca53116%40googlegroups.com.