On Wed, Mar 06, 2019 at 12:25:10PM -0500, Jesse Glick wrote:
> On Wed, Mar 6, 2019 at 3:59 AM Thomas Weißschuh wrote:
>> * (If it can, but it is called without a block, {@link StepContext#hasBody} will be false.)
>>
>> Also official steps like "stage" accept both forms.
>
> Ah forgot that this was introduced for the `stage` step trick. My
> advice had actually been to keep `stage` as is and introduce
> block-scoped `label`. Best to not use this facility and keep each step
> either exclusively block-scoped or non-block-scoped.
Is there a chance of it breaking in the future, now that it has been published
and documented?
>> The plugin is *very* generic.
>> (it only looks at the build as a series of nodes/steps, without any
>> assumptions about their content)
>
> So what is it doing, exactly? This smells like something that (if
> needed at all) should be built into the syntax, not done as a `Step`.
Now that you are asking :-)
The plugin exposes the internal processes of Jenkins
(runs, queues, workflows) to a general distributed tracing system.
The goal is to have a complete, end-to-end linked trace over the whole CI/CD pipeline,
including the SCM system, all the different steps inside Jenkins, all the steps
of the build systems executed by Jenkins, asynchronous processes triggered by
the build, executors spun up for the build, etc...
You may remember our discussion on this list about having per step environment
variables and the resulting implementation of the StepEnvironmentContributor
Extensionpoint. This was for the same plugin and allows the plugin to
communicate with other plugins in maven, SonarQube, docker etc.
The goal is to have increased transparency for the users, better monitoring and accounting.
Currently inside Jenkis Pipelines all Steps are recorded (in addition to the
other parts), enriched with information from within Jenkins and added to the
tracing system.
For this reason it keeps a database of currently running steps and their
associated tracing datastructure
(care is taken not to leak memory references to core Jenkins objects).
However there are cases where the information available out of the box is not
sufficient.
For this usecase the custom step provides two functionalities, when called with
or without a block.
It can be used to "synthesize" a step for the tracing system, which is useful
if there is no native step with the desired scope available at the moment.
For example when a new stage is not desired, or for use in a global
pipeline library, as steps from libraries do not end up as new FlowNodes and so
are not traced explicitly out of the box.
trace(tags: ["command.type": "something"]) {
sh '...'
}
The other syntax (without a block) allows users and pipeline library authors to
enrich the currently active tracing scope with custom information.
This helps to keep the amount of tracing scopes smaller, also it allows for a
better search experience.
# all nested steps modify the tags of the "stage" scope
stage("someStage") {
# same way as above
trace(tags: ["foo": 1])
# it also returns an object that can be used from groovy
trace().setTag("foo", 1)
trace().tags["bar"] = 2
}
For this last part I wanted to implement a shorthand syntax without the
required braces.
Can you elaborate on "building something into the syntax"?
Is it something I can already do?
>> What do you think of having steps (optionally, decided by the step author)
>> available as something like global variables?
>> This would allow plugin authors to provide this functionality
>> (for which they currently do implement GlobalVariables)
>> without the disadvantages and without a tight dependency on Cps.
> Even if there were not a literal compile-and-link dependency on
> `workflow-cps` the semantics would be inherently tied to details of
> that model.
As it would only be syntactic sugar, this would be fine for my particular
usecase. If it does not fit the general semantics then I will have to do
without.
The other case I mentioned, where GlobalVariables override Steps during lookup
does actually match the behaviour of normal Groovy. Somehow I got my previous
tests there wrong.
So as for the triply overloaded symbol, I will have to do with the current state.