Where to find source for Declarative Pipeline post actions?

I want to learn more about how Jenkins internals work, mainly considering the post {} block for Declarative pipelines. Specifically, I want to learn more about how Jenkins determines if the “fixed” post-action should be invoked. I’ve dug through many of the pipeline and plugin repositories on GitHub but am struggling to find where this is implemented.

Example:

pipeline {
  stages {}
  post {
    fixed { <--- where is this implemented?
      ...
    }
  }
}

Where can I find the source for how this is implemented?

Thanks!

Surprisingly not implemented in Java.

1 Like

Thanks! Out of curiosity, is there something I could have done or known better to have found this plugin or that this was the place I needed to look?

In the Snippet Generator or Declarative Directive Generator, if an option has a help button and you click that, it usually shows the name of the plugin in which the thing is defined. For example, " (from Pipeline: Declarative)".

However, the help button for the “post: Post Stage or Build Conditions” directive seems to be nonfunctional. When I use the developer features of a Web browser to view the HTML DOM for the help button, it is defined like this:

<a tooltip="Help" helpurl="/jenkins/descriptor/org.jenkinsci.plugins.pipeline.modeldefinition.generator.PostDirective/help" href="#" class="jenkins-help-button" tabindex="9999" style="" title="Help"><span>?</span></a>

which at least hints to a “pipeline.modeldefinition” plugin. At that point, one can search for org.jenkinsci.plugins.pipeline.modeldefinition.generator PostDirective in the GitHub “jenkinsci” organization. This requires a GitHub account but finds PostDirective.java:

https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/15978cd172a8d34e2cd6bf8a6bfeaa5514d44dad/pipeline-model-definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/generator/PostDirective.java#L25-L36

The “fixed” condition is defined in this same repository and can be found by clicking “Go to file” and typing “fixed”.

Although the source code is in the same repository in this case, it is compiled to a separate plugin. The relevant code in PostDirective.getPossibleConditions calls BuildCondition.all():

https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/15978cd172a8d34e2cd6bf8a6bfeaa5514d44dad/pipeline-model-definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/generator/PostDirective.java#L74

BuildCondition is defined as an extension point:

https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/15978cd172a8d34e2cd6bf8a6bfeaa5514d44dad/pipeline-model-extensions/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/model/BuildCondition.java#L53

which is in the pipeline-model-extensions plugin. The Extensions Index lists the classes that implement BuildCondition, including:

Apparently, the extension points are defined in Java in the pipeline-model-extensions plugin, and then they are implemented in Groovy in the pipeline-model-definition plugin.

It is unfortunate that the Extensions Index does not pinpoint the file in which each class is defined. I don’t know whether the plugin build processes for Java and Groovy code can save that information such that the Extensions Index could display it.

1 Like

That’s quite the investigation you did to find the plugin/source. Thanks for the detailed description of the steps you took!