Home > other >  Jenkins file GROOVY error -- java.lang.NullPointerException: Cannot invoke method tokenize() on null
Jenkins file GROOVY error -- java.lang.NullPointerException: Cannot invoke method tokenize() on null

Time:02-15

I am facing one issue while building my project in jenkins.

Actually recently we have migrated our code from GITLAB to GITHUB. Earlier we were using variables by which are directly available in GITLAB. But now we are accessing the Webhook data by post content parameter in jenkins. When we are pushing the code from IDE to GITHUB my pipeline is working fine. But when I am running my pipeline using build with parameter. This line of code is creating issue env.gitLabSourceBranch = env.GIT_BRANCH.tokenize('/')[2] env.GIT_BRANCH is coming from the post Webhook trigger. I want a solution that when we trigger pipeline as build with parameter it should take the GITBRANCH value as null and bypass this firstline.

CodePudding user response:

I want a solution that when we trigger pipeline as build with parameter it should take the GITBRANCH value as null and bypass this firstline.

Try this:

env.gitLabSourceBranch = env.GIT_BRANCH ? env.GIT_BRANCH.tokenize('/')[2] : null
  • Related