Re: MissingMethodException while using shared libraries

2019-03-01 Thread Kaliyug Antagonist
Instantiating every time works well, I had tried that earlier but that 
isn't the way I wish to go :(

On Friday, March 1, 2019 at 9:20:09 AM UTC+1, Reinhold Füreder wrote:
>
> Hi,
>
>  
>
> a naive quick guess is that you are using too much groovy, but Jenkins 
> pipeline code is -- well -- not fully groovy…
>
>  
>
> => Maybe try to replace the fields like:
>
>  @Field final BitbucketBuildOperationsHandler bitbucketUtilities = 
> new BitbucketBuildOperationsHandler(this,env)
>
> … in “bitbucketUtilities.groovy” with explicitly instantiating it in each 
> method, e.g.:
>
> @NonCPS
>
> def notifyBuildFail(String message, String displayName) {
>
>  
>
> //Remove
>
> println "bitbucketUtilities global vars, env: "+env
>
>  
>
> validateCall(this, message, displayName)
>
>  
>
> BitbucketBuildOperationsHandler bitbucketUtilities = new 
> BitbucketBuildOperationsHandler(this,env)
>
> bitbucketUtilities.notifyBuildFail(message, displayName)
>
> }
>
>  
>
> Please also note that in @NonCPS annotated methods you may not call 
> pipeline steps AFAIK, “echo” step being a bit of an exception maybe?
>
>  
>
> HTH Reinhold
>
>  
>
> *From:* jenkins...@googlegroups.com  <
> jenkins...@googlegroups.com > *On Behalf Of *Kaliyug 
> Antagonist
> *Sent:* Freitag, 1. März 2019 08:51
> *To:* Jenkins Users >
> *Subject:* MissingMethodException while using shared libraries
>
>  
>
> Cloudbees 2.121.3.1
>
>  
>
> Partial Jenkinsfile of the main component that is failing viz. Alfaclient:
>
> properties([parameters([string(defaultValue: "", description: "List of 
> components", name: 'componentsToUpdate'),
>
> string(defaultValue: 
> "refs%2Fheads%2Fproject%2Fintegration", description: "BuildInfo CommitID", 
> name: 'commitId'),
>
> string(defaultValue: "", description: "Tag to 
> release, e.g. 1.1.0-integration", name: 'releaseTag'),
>
> string(defaultValue: "", description: "Forked 
> buildInfo repo. Be aware right commit ID!!!", name: 'fork')]),
>
> [$class: 'BuildDiscarderProperty', strategy: [$class: 
> 'LogRotator', artifactDaysToKeepStr: '', artifactNumToKeepStr: '', 
> daysToKeepStr: '7', numToKeepStr: '5']],
>
> disableConcurrentBuilds()])
>
>  
>
> @Library(['jenkins-shared-utilities@integration/CICD-344-refactor-bitbucket-notify-handler','jenkins-shared-stages@integration/CICD-344-refactor-bitbucket-notify-handler','jenkins-shared-pipelines@integration/CICD-344-refactor-bitbucket-notify-handler'])
>  _
>
> .
>
> .
>
> .
>
> returnValue = componentPipeline {
>
> componentsToUpdate = rewriteDependencies
>
> commitId = buildInfoCommitId
>
> runOnForkedRepo = forkedRepo
>
> }
>
>  
>
> The componentPipeline in the above code is a scripted pipeline located in 
> vars of *jenkins-shared-pipelines* The partial Jenkinsfile(which doesn't 
> do much!) of jenkins-shared-pipelines
>
> #!groovy
>
>  
>
> @Library(['jenkins-shared-utilities@integration/CICD-344-refactor-bitbucket-notify-handler','jenkins-shared-stages@integration/CICD-344-refactor-bitbucket-notify-handler'])
>  _
>
>  
>
> Partial code for componentPipeline:
>
> def call(body) {
>
> def config = [:]
>
> body.resolveStrategy = Closure.DELEGATE_FIRST
>
> def componentName = null
>
> body.delegate = config
>
> body()
>
> def rewriteDependency = config.componentsToUpdate
>
> def buildInfoCommitId = config.commitId
>
> def forkedBuildInfo = config.runOnForkedRepo
>
>  
>
> def PIPELINE_NAME = "Component Pipeline"
>
> .
>
> .
>
> .
>
> setupSharedUtils(callingScript: this)
>
> .
>
> .
>
> .
>
> def build_status = "ok"
>
> stage(CLEAN_STAGE) {
>
> .
>
> .
>
> .
>
> bitbucketUtilities.notifyBuildStart("Build ${env.BUILD_ID} 
> started at ${env.BUILD_TIMESTAMP}", PIPELINE_NAME)
>
>  
>
> }
>
> stage(GET_BUILD_INFO) {
>
> .
>
> .
>
> .
>
> build_status = "${COMPILE_STAGE} failed in build ${env.BUILD_ID} 
> with exit code ${exit_code}"
>
> bitbucketUtilities.notifyBuildFail(build_status, PIPELINE_NAME)
>
>  
>
> }   
>
>  
>
> }
>
>  
>
> Now comes the main library viz. *jenkins-shared-utilities*. It has the 
> following structure: 
>
>  
>
> *vars* containing scripts that would act as global variables for 
> components like *Alfaclient*.
>
> bitbucketUtilities.groovy
>
> import groovy.transform.Field
>
> import com.jenkins.utilities.bitbucket.*
>
> import com.cloudbees.groovy.cps.NonCPS
>
>  
>
> @Field final String STEP_NAME = getClass().getName()
>
> @Field final BitbucketBuildOperationsHandler bitbucketUtilities = new 
> BitbucketBuildOperationsHandler(this,env)
>
>  
>
> @NonCPS
>
> def notifyBuildStart(String message, String displayName) {
>
>  
>
> //Remove
>
> println "

RE: MissingMethodException while using shared libraries

2019-03-01 Thread Reinhold Füreder
Hi,

a naive quick guess is that you are using too much groovy, but Jenkins pipeline 
code is -- well -- not fully groovy…

=> Maybe try to replace the fields like:

 @Field final BitbucketBuildOperationsHandler bitbucketUtilities = new 
BitbucketBuildOperationsHandler(this,env)
… in “bitbucketUtilities.groovy” with explicitly instantiating it in each 
method, e.g.:

@NonCPS

def notifyBuildFail(String message, String displayName) {



//Remove

println "bitbucketUtilities global vars, env: "+env



validateCall(this, message, displayName)



BitbucketBuildOperationsHandler bitbucketUtilities = new 
BitbucketBuildOperationsHandler(this,env)

bitbucketUtilities.notifyBuildFail(message, displayName)

}

Please also note that in @NonCPS annotated methods you may not call pipeline 
steps AFAIK, “echo” step being a bit of an exception maybe?

HTH Reinhold

From: jenkinsci-users@googlegroups.com  On 
Behalf Of Kaliyug Antagonist
Sent: Freitag, 1. März 2019 08:51
To: Jenkins Users 
Subject: MissingMethodException while using shared libraries


Cloudbees 2.121.3.1



Partial Jenkinsfile of the main component that is failing viz. Alfaclient:

properties([parameters([string(defaultValue: "", description: "List of 
components", name: 'componentsToUpdate'),

string(defaultValue: 
"refs%2Fheads%2Fproject%2Fintegration", description: "BuildInfo CommitID", 
name: 'commitId'),

string(defaultValue: "", description: "Tag to release, 
e.g. 1.1.0-integration", name: 'releaseTag'),

string(defaultValue: "", description: "Forked buildInfo 
repo. Be aware right commit ID!!!", name: 'fork')]),

[$class: 'BuildDiscarderProperty', strategy: [$class: 
'LogRotator', artifactDaysToKeepStr: '', artifactNumToKeepStr: '', 
daysToKeepStr: '7', numToKeepStr: '5']],

disableConcurrentBuilds()])



@Library(['jenkins-shared-utilities@integration/CICD-344-refactor-bitbucket-notify-handler','jenkins-shared-stages@integration/CICD-344-refactor-bitbucket-notify-handler','jenkins-shared-pipelines@integration/CICD-344-refactor-bitbucket-notify-handler'])
 _

.

.

.

returnValue = componentPipeline {

componentsToUpdate = rewriteDependencies

commitId = buildInfoCommitId

runOnForkedRepo = forkedRepo

}



The componentPipeline in the above code is a scripted pipeline located in vars 
of jenkins-shared-pipelines The partial Jenkinsfile(which doesn't do much!) of 
jenkins-shared-pipelines

#!groovy



@Library(['jenkins-shared-utilities@integration/CICD-344-refactor-bitbucket-notify-handler','jenkins-shared-stages@integration/CICD-344-refactor-bitbucket-notify-handler'])
 _



Partial code for componentPipeline:

def call(body) {

def config = [:]

body.resolveStrategy = Closure.DELEGATE_FIRST

def componentName = null

body.delegate = config

body()

def rewriteDependency = config.componentsToUpdate

def buildInfoCommitId = config.commitId

def forkedBuildInfo = config.runOnForkedRepo



def PIPELINE_NAME = "Component Pipeline"

.

.

.

setupSharedUtils(callingScript: this)

.

.

.

def build_status = "ok"

stage(CLEAN_STAGE) {

.

.

.

bitbucketUtilities.notifyBuildStart("Build ${env.BUILD_ID} started 
at ${env.BUILD_TIMESTAMP}", PIPELINE_NAME)



}

stage(GET_BUILD_INFO) {

.

.

.

build_status = "${COMPILE_STAGE} failed in build ${env.BUILD_ID} 
with exit code ${exit_code}"

bitbucketUtilities.notifyBuildFail(build_status, PIPELINE_NAME)



}



}



Now comes the main library viz. jenkins-shared-utilities. It has the following 
structure:



vars containing scripts that would act as global variables for components like 
Alfaclient.

bitbucketUtilities.groovy

import groovy.transform.Field

import com.jenkins.utilities.bitbucket.*

import com.cloudbees.groovy.cps.NonCPS



@Field final String STEP_NAME = getClass().getName()

@Field final BitbucketBuildOperationsHandler bitbucketUtilities = new 
BitbucketBuildOperationsHandler(this,env)



@NonCPS

def notifyBuildStart(String message, String displayName) {



//Remove

println "bitbucketUtilities global vars, env: "+env

validateCall(this, message, displayName)



bitbucketUtilities.notifyBuildStart(message, displayName)

}



@NonCPS

def notifyBuildSuccess(String message, String displayName) {



//Remove

println "bitbucketUtilities global vars, env: "+env



 validateCall(this, message, displayName)



bitbucketUtilities.notifyBuildSuccess(message, displayName)

}



@NonCPS

def notifyBuildFail(String message, String displayName) {



//Remove

println "bitbucketUtilities global vars, env: "+env



validateCall(this, message, displayName)



bit