Skip to content

Commit

Permalink
Merge branch 'refs/heads/feature/1180-workflows' into release/4.8
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoraboeuf committed May 13, 2024
2 parents 7e209eb + fd1f5e3 commit c4aff5b
Show file tree
Hide file tree
Showing 275 changed files with 19,655 additions and 2,654 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ target
.classpath
.settings
work*/
!workflows
.DS_Store
build
.gradle
Expand Down
6 changes: 5 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,15 @@ pipeline {
post {
always {
recordIssues(tools: [kotlin(), javaDoc(), java()])
// Build validation stamp
// Build validation stamps
ontrackCliValidateTests(
stamp: 'BUILD',
pattern: '**/build/test-results/**/*.xml',
)
ontrackCliValidateTests(
stamp: 'UI_UNIT',
pattern: 'ontrack-web-core/reports/*.xml',
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.nemerosa.ontrack.common

import org.apache.commons.lang3.exception.ExceptionUtils

private const val MAX_STACK_HEIGHT = 20
private const val MAX_STACK_LENGTH = 2000

fun reducedStackTrace(error: Throwable) =
ExceptionUtils.getStackFrames(error).take(MAX_STACK_HEIGHT).joinToString("\n").take(MAX_STACK_LENGTH)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[[appendix-workflow-node-executors]]
=== Workflow nodes executors

Find below the list of all workflow node executors and their configurations.

include::workflow-node-executors/index.adoc[]
2 changes: 2 additions & 0 deletions ontrack-docs/src/docs/asciidoc/appendixes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ include::appendix-events.adoc[]

include::appendix-notifications.adoc[]

include::appendix-workflow-node-executors.adoc[]

// include::appendix-deprecations.adoc[]

// include::appendix-roadmap.adoc[]
Expand Down
158 changes: 158 additions & 0 deletions ontrack-docs/src/docs/asciidoc/feature-workflows.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
[[workflows]]
=== Workflows

Workflows allow the execution of several actions orchestrated in a DAG (directed acyclic graph).

[NOTE]
====
As of version 4.8, workflows can only be triggered using the <<notifications>>.
There is already some partial and undocumented support through API calls to run some standalone workflows but this is very experimental.
====

[[workflow-definitions]]
==== Workflows definitions

To run a workflow, you can define a notification whose channel is `workflow`.

This can be done through the UI or as code.

[NOTE]
====
Workflows definitions in the UI is only supported in the Next UI of Ontrack and won't be supported in the legacy UI.
====

A workflow:

* has a name, used for information and display purposes
* has a list of nodes

Each node:

* has an ID which must be unique inside the workflow
* an executor ID that points to a _workflow node executor_
* some data for the _workflow node executor_
* a list of parent nodes

The list of parent nodes is what defines the workflow DAG.

[NOTE]
====
When defining or running workflows, graph cycles are automatically detected.
====

Workflows notifications can be defined as code, like all other <<notifications,notifications>>.

For example:

[source,yaml]
----
channel: workflow
channelConfig:
workflow:
name: My workflow
nodes:
- id: ticket
executorId: notification
data:
channel: jira-creation
channelConfig:
# Configuration for the ticket creation
- id: mail
executorId: notification
parents:
- id: ticket
data:
channel: mail
channelConfig:
# Configuration for the mail
template: |
Link to ticket: ${workflow.ticket?path=url}
----

[[workflow-executors]]
==== Workflows nodes executors

A _workflow node executor_ is a component which is responsible to "run a node".

See <<appendix-workflow-node-executors>> for a list of all existing workflow node executors.

[[workflow-templates]]
==== Workflow templating

Many elements in the workflow definition are subject to <<appendix-templating,templating>>.

The workflow name is itself considered as a template when being run as a notification (which is the default in 4.8).

When using <<workflow-node-executor-notification,notifications as node executors>>, the configuration elements are templates as usual.

Note that for a workflow notification, the event is passed as a context element and all template functions and sources are available.

Additionally, when a notification is run as part of a workflow, a new templating function is available: `workflow`.

This function allows the access to the output data of any successful node in the workflow.

For example, let's take a workflow which:

* creates a ticket in Jira
* then send a link to this ticket with an email



[source,yaml]
----
channel: workflow
channelConfig:
workflow:
name: My workflow
nodes:
- id: ticket
executorId: notification
data:
channel: jira-creation
channelConfig:
# Configuration for the ticket creation
- id: mail
executorId: notification
parents:
- id: ticket
data:
channel: mail
channelConfig:
# Configuration for the mail
template: |
Link to ticket: ${workflow.ticket?path=url}
----

The `ticket` node runs and set some information in its output (see <<notification-backend-jira-creation>> for the full details), including a `url` property.

Then, the `mail` node is run and is using the `notification` _workflow node executor_ again, with the <<notification-backend-mail,`mail` channel>> being configured to send a mail.

This channel can use the `template` for the mail's body and is using the `workflow` function to get the output of the `ticket` node and the `url` property of its output.

[[workflow-management]]
==== Workflows management

The progress of running workflows can be accessed in _Information > Workflow audit_.

Clicking on a workflow displays more details about its current status, node per node.

When using the _workflow notification channel_, the workflow status link is also accessible from the _Information > Notification recordings_, when selecting the notification.

[[workflow-settings]]
==== Workflows settings

Workflow statuses are saved by default for 14 days.

To change this value, you can go to _System > Settings > Workflows_.

This can also be defined as code using <<casc,CasC>>:

[source,yaml]
----
ontrack:
config:
settings:
workflows:
retentionDuration: 1209600000 # 14 days in ms
----
2 changes: 2 additions & 0 deletions ontrack-docs/src/docs/asciidoc/features.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ include::feature-branches.adoc[]

include::feature-scm.adoc[]

include::feature-workflows.adoc[]

//include::usage-validation-stamps.adoc[]
//
//include::usage-promotion-levels.adoc[]
Expand Down
2 changes: 2 additions & 0 deletions ontrack-docs/src/docs/asciidoc/notifications/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
* <<notification-backend-mail,Mail (`mail`)>>
* <<notification-backend-slack,Slack (`slack`)>>
* <<notification-backend-webhook,Webhook (`webhook`)>>
* <<notification-backend-workflow,Workflow (`workflow`)>>

include::notification-backend-jenkins.adoc[]
include::notification-backend-jira-creation.adoc[]
include::notification-backend-jira-service-desk.adoc[]
include::notification-backend-mail.adoc[]
include::notification-backend-slack.adoc[]
include::notification-backend-webhook.adoc[]
include::notification-backend-workflow.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

This channel is used to trigger remote Jenkins jobs with some parameters.



_This channel does not use the custom template._

Links:

* <<integration-jenkins-notifications,Jenkins notifications>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

This channel is used to create a Jira Service Desk ticket.



_This channel does not use the custom template._

Configuration:

* **configName** - String - required - Name of the Jira configuration to use for the connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

Calling an external webhook



_This channel does not use the custom template._

Configuration:

* **name** - String - required - Name of the webhook to use
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[[notification-backend-workflow]]
==== Workflow (`workflow`)

Launches a workflow



_This channel does not use the custom template._

Configuration:

* **workflow** - Object - required - Workflow to run

** **name** - String - required - Display name for the workflow

** **nodes** - List - required - List of nodes in the workflow

*** **data** - JSON - required - Raw data associated with the node, to be used by the node executor.

*** **executorId** - String - required - ID of the executor to use

*** **id** - String - required - Unique ID of the node in its workflow.

*** **parents** - List - required - List of the IDs of the parents for this node

**** **id** - String - required - ID of the parent node

Output:

* **workflowInstanceId** - String - required - ID of the workflow instance. Can be used to track the progress and outcome of the workflow.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[[appendix-workflow-node-executors-index]]
==== List of workflow node executors

* <<workflow-node-executor-mock,Mock (mock)>>
* <<workflow-node-executor-notification,Notification (notification)>>

include::workflow-node-executor-mock.adoc[]
include::workflow-node-executor-notification.adoc[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[[workflow-node-executor-mock]]
==== Mock (mock)

Executor used to mock some actions for the nodes. Mostly used for testing.

Configuration:

* **error** - Boolean - required - Raising an error during the execution of the node

* **text** - String - required - Text associated with the node

* **waitMs** - Long - required - Time to wait for the execution of the node

Output:

* **text** - String - required - text field

Example:

[source]
----
executorId: mock
data:
text: Some text to store
waitMs: 500
error: false
----
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[[workflow-node-executor-notification]]
==== Notification (notification)

Wraps a notification in a workflow node.

The output of this execution is exactly the output
of the notification channel.

Configuration:

* **channel** - String - required - Notification channel ID

* **channelConfig** - JSON - required - Notification channel configuration

* **template** - String - optional - Optional template for the notification

Example:

[source]
----
executorId: notification
data:
channel: slack
channelConfig:
channel: "#my-channel"
template: |
Message template
----
2 changes: 1 addition & 1 deletion ontrack-extension-auto-versioning/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies {
implementation(project(":ontrack-repository-support"))
implementation(project(":ontrack-rabbitmq"))
implementation("io.micrometer:micrometer-core")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") // TODO Remove when removing the Yaml class
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.apache.commons:commons-lang3")
implementation("jakarta.annotation:jakarta.annotation-api")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.nemerosa.ontrack.extension.av.audit

import net.nemerosa.ontrack.common.reducedStackTrace
import net.nemerosa.ontrack.extension.av.dispatcher.AutoVersioningOrder
import org.apache.commons.lang3.exception.ExceptionUtils
import org.slf4j.Logger
import org.slf4j.LoggerFactory

Expand All @@ -11,14 +11,6 @@ abstract class AbstractAutoVersioningAuditService(

protected val logger: Logger = LoggerFactory.getLogger(AutoVersioningAuditService::class.java)

companion object {
private const val MAX_STACK_HEIGHT = 20
private const val MAX_STACK_LENGTH = 2000

fun reducedStackTrace(error: Throwable) =
ExceptionUtils.getStackFrames(error).take(MAX_STACK_HEIGHT).joinToString("\n").take(MAX_STACK_LENGTH)
}

override fun onQueuing(order: AutoVersioningOrder, routing: String, cancelling: Boolean) {
if (cancelling) {
store.cancelQueuedOrders(order)
Expand Down
Loading

0 comments on commit c4aff5b

Please sign in to comment.