Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-52022

Are we able to define a method in declarative Jenkinsfile(which will be a part of our source code) and call it in shared library

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      I want to specify a method in jenkinsfile, which will be part of my source code and I want to call that method at any specific stage in Shared-library. Is there anyway, we could do that in case of "declarative pipelines" .

                                     Can I create a method inside the build pipeline shown in below attachment

        Attachments

          Activity

          Hide
          reinholdfuereder Reinhold Füreder added a comment -

          Srinath Palasani I think you might want to have a method or custom step in the shared library that takes a block/closure as argument (which in turn executes the project or concrete Jenkinsfile specific code), see e.g. https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-custom-steps

          Show
          reinholdfuereder Reinhold Füreder added a comment - Srinath Palasani I think you might want to have a method or custom step in the shared library that takes a block/closure as argument (which in turn executes the project or concrete Jenkinsfile specific code), see e.g. https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-custom-steps
          Hide
          abayer Andrew Bayer added a comment -

          As Reinhold said, you can define methods in shared libraries and use them in your Jenkinsfile, but not the other way around.

          Show
          abayer Andrew Bayer added a comment - As Reinhold said, you can define methods in shared libraries and use them in your Jenkinsfile, but not the other way around.
          Hide
          srinath45 Srinath Palasani added a comment -

          Is there anyway, I can define methods in Jenkins file and call it from shared library. This is because, we have many developers and each of them wants to use different content in their method in Jenkins file in their branch. So, this is not the case, where I can put method in shared library and execute it. I will use some method in shared library and every developer will same method name in their Jenkins file and they can put any content in that method. Thank you,

          Show
          srinath45 Srinath Palasani added a comment - Is there anyway, I can define methods in Jenkins file and call it from shared library. This is because, we have many developers and each of them wants to use different content in their method in Jenkins file in their branch. So, this is not the case, where I can put method in shared library and execute it. I will use some method in shared library and every developer will same method name in their Jenkins file and they can put any content in that method. Thank you,

            People

            Assignee:
            abayer Andrew Bayer
            Reporter:
            srinath45 Srinath Palasani
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: