Calling functions in Jenkins Shared Libraries

192 views
Skip to first unread message

Chris Shannon

unread,
Aug 3, 2020, 2:56:28 PM8/3/20
to Jenkins Users

I've been using Jenkins shared libraries for quite a while, but something just popped up which is confusing me quite a bit. Instead of just creating steps, I'm now trying to create a full declarative pipeline inside the shared library.


In any case, what I'm finding is that this works great when my pipeline is defined directly inside the call method. As soon as I do a simple function call, I get errors like:


hudson.remoting.ProxyException: groovy.lang.MissingPropertyException: No such property: any for class

To be clear, here is working code:


def call() {
  pipeline {
    agent any

    stages {
      stage("Stage") {
        steps {
          echo "hi"
        }
      }
    }
  }
}


And here is non-working code:


def call() {
  execute()
}

def execute() {
  pipeline {
    agent any

    stages {
      stage("Stage") {
        steps {
          echo "hi"
        }
      }
    }
  }
}


For reasons beyond this post, we are trying to add some commonality and argument checking to our steps, which is why I'd like to be able to use that concept of the extra function call..


Any help/pointers would be much appreciated.


Thanks!

Chris

mar...@gmail.com

unread,
Sep 23, 2021, 2:03:12 PM9/23/21
to Jenkins Users
Have you discovered anything?  See my recent post today about similar issue.  You can follow it.
Reply all
Reply to author
Forward
0 new messages