Skip to content

Commit 6389666

Browse files
author
Divya Bhushan
authored
Docs: Adding docs for Pre/Post-Build tasks (#1690)
1 parent 34fe8cc commit 6389666

File tree

5 files changed

+529
-164
lines changed

5 files changed

+529
-164
lines changed

docs/SUMMARY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
* [Job and Cronjob](user-guide/creating-application/deployment-template/job-and-cronjob.md)
3939
* [Workflow](user-guide/creating-application/workflow/README.md)
4040
* [CI Pipeline](user-guide/creating-application/workflow/ci-pipeline.md)
41+
* [Pre-Build/Post-Build tasks](user-guide/creating-application/workflow/ci-build-pre-post-plugins.md)
42+
* [CI Pipeline (Legacy)](user-guide/creating-application/workflow/ci-pipeline-legacy.md)
43+
* [Automated test suite integration in CI](user-guide/creating-application/workflow/automated-test.md)
4144
* [CD Pipeline](user-guide/creating-application/workflow/cd-pipeline.md)
4245
* [Config Maps](user-guide/creating-application/config-maps.md)
4346
* [Secrets](user-guide/creating-application/secrets.md)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Automated Test suite integration in the CI step using devtron-ci.yaml
2+
3+
Users can run the test case using the Devtron dashboard or by including the test cases in the devtron.ci.yaml file in the source git repository. For reference, check: [https://github.com/kumarnishant/getting-started-nodejs/blob/master/devtron-ci.yaml](https://github.com/kumarnishant/getting-started-nodejs/blob/master/devtron-ci.yaml)
4+
5+
The test cases given in the script will run before the test cases given in the devtron.ci.yaml
6+
7+
![](../../../.gitbook/assets/yaml%20%283%29.jpg)
8+
9+
| Field | Description |
10+
| :--- | :--- |
11+
| `version` | specify the version of yaml |
12+
| `appliesTo` | applies the changes to a specified branch |
13+
| `type` | branch type on which changes are to be applied, it can be **BRANCH\_FIXED** or **TAG\_PATTERN** |
14+
| `value` | branch name on which changes are to be applied, it can take a value as the name of branch \(“master”\) or as a regular expression \("%d.%d.%d-rc"\) |
15+
| `script` | A script which you want to execute, you can also execute the docker commands here |
16+
| `beforeDockerBuildStages` | script to run before the docker build step |
17+
| `afterDockerBuildStages` | script to run after the docker build step |
18+
| `outputLocation` | The location where you want to see the output of the report of Test cases |
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Pre-Build and Post-Build stages
2+
3+
The CI pipeline includes Pre and Post-build steps to validate and introduce checkpoints in the build process.
4+
5+
The pre/post plugins allow you to execute some standard tasks, such as Code analysis, Load testing, Security scanning, and so on.
6+
You can build custom pre/post tasks or use one from the standard preset plugins provided by Devtron.
7+
8+
## Before you begin
9+
10+
Create a [CI build pipeline](./ci-pipeline2.md) if you haven't done that already!
11+
12+
## Configuring Pre/Post-build stages
13+
14+
Each Pre/Post-build stage is executed as a series of events called tasks and includes custom scripts.
15+
You could create one or more tasks that are dependent on one another for execution. In other words, the output variable of one task can be used as an input for the next task to build a CI runner.
16+
17+
The tasks will run following the execution order.
18+
19+
> The tasks may be re-arranged by using drag-and-drop; however, the order of passing the variables must be followed.
20+
21+
| Stage | Task |
22+
| :--- | :--- |
23+
| Pre-Build/Post-Build | <ol><li>Create a task from - [Preset Plugin](#preset-plugins)<ul><li>Sonarqube</li><li>K6 Load testing</li></ul></li><li>Create a task from - [Execute Custom script](#execute-custom-script)<ul><li>[Custom script - Shell](#custom-script-shell)</li><li>[Custom script - Container image](#custom-script-container-image)</li></ul></li></ol> |
24+
25+
## Creating a task
26+
27+
1. Go to **Applications** and select your application from the **Devtron Apps** tabs.
28+
2. From the **App Configuration** tab select **Workflow Editor**.
29+
3. Select the build pipeline for editing the stages.
30+
31+
> Devtron CI pipeline includes the following build stages:
32+
>
33+
> * Pre-build stage: The tasks in this stage run before the image is built.
34+
> * Build stage: In this stage, the build is triggered from the source code that you provide.
35+
> * Post-build stage: The tasks in this stage are triggered once the build is complete.
36+
37+
You can create a task either by selecting one of the available preset plugins or by creating a custom script.
38+
39+
[Preset plugins](#preset-plugins) | [Execute custom script](#execute-custom-script)
40+
41+
### Preset plugins
42+
43+
**Prerequisite**: Set up Sonarqube, or get the API keys from an admin.
44+
45+
The example shows a Post-build stage with a task created using a preset plugin - Sonarqube.
46+
47+
1. On the **Edit build pipeline** screen, select the **Post-build stage** (or Pre-build).
48+
2. Select **+ Add task**.
49+
3. Select **Sonarqube** from **PRESET PLUGINS**.
50+
51+
![Preset plugin - Sonarqube](https://devtron-public-asset.s3.us-east-2.amazonaws.com/plugins/preset-plugin-sonarqube.png)
52+
53+
| Field name | Required/Optional | Field description |
54+
| --- | --- | --- |
55+
| Task name | Required | A relevant name for the task |
56+
| Description | Optional | A descriptive message for the task |
57+
| Input variables | Optional | VALUE: A value for the input variable. The value may be any of the values from the previous build stages, a global variable, or a custom value |
58+
| Trigger/Skip Condition | Optional | A conditional statement to execute or skip the task |
59+
60+
Select **Update Pipeline**.
61+
62+
### Execute custom script
63+
64+
1. On the **Edit build pipeline** screen, select the **Pre-build stage**.
65+
2. Select **+ Add task**.
66+
3. Select **Execute custom script**.
67+
68+
The task type of the custom script may be a [Shell](#custom-script---shell) or a [Container image](#custom-script---container-image).
69+
70+
#### Custom script - Shell
71+
72+
* Select the **Task type** as **Shell**.
73+
74+
Consider an example that creates a Shell task to stop the build if the database name is not "mysql". The script takes 2 input variables, one is a global variable (`DOCKER_IAMGE`), and the other is a custom variable (`DB_NAME`) with a value "mysql".
75+
The task triggers only if the database name matches "mysql".
76+
If the trigger condition fails, this Pre-build task will be skipped and the build process will start.
77+
The variable `DB_NAME` is declared as an output variable that will be available as an input variable for the next task.
78+
The task fails if `DB_NAME` is not equal to "mysql".
79+
80+
![Custom script - Shell](https://devtron-public-asset.s3.us-east-2.amazonaws.com/plugins/Custom-script-Shell.png)
81+
82+
| Field name | Required/Optional | Field description |
83+
| --- | --- | --- |
84+
| Task name | Required | A relevant name for the task |
85+
| Description | Optional | A descriptive message for the task |
86+
| Task type | Optional | Shell: Custom shell script goes here |
87+
| Input variables | Optional | <ul><li>**Variable name**: Alphanumeric chars and (_) only</li><li>**Source or input value**: The variable's value can be global, output from the previous task, or a custom value. <br>Accepted data types include: STRING \| BOOL \| NUMBER \| DATE</li><li>**Description**: Relevant message to describe the variable.</li></ul> | The input variables will be available as env variables |
88+
| Trigger/Skip condition | Optional | A conditional statement to execute or skip the task |
89+
| Script | Required | Custom script for the Pre/Post-build tasks |
90+
| Output directory path | | Optional | Directory path for the script output files such as logs, errors, etc. |
91+
| Output variables | Optional | Environment variables that are passed as input variables for the next task. <ul><li>Pass/Failure Condition (Optional): Conditional statements to determine the success/failure of the task. A failed condition stops the execution of the next task and/or build process</li></ul> |
92+
93+
* Select **Update Pipeline**.
94+
95+
Here is a screenshot with the failure message from the task:
96+
97+
![Pre-Build task failure](https://devtron-public-asset.s3.us-east-2.amazonaws.com/plugins/custom-script-shell-task-failed.png)
98+
99+
#### Custom script - Container image
100+
101+
* Select the **Task type** as **Container image**.
102+
103+
This example creates a Pre-build task from a container image. The output variable from the previous task is available as an input variable.
104+
105+
![Custom script - Container image](https://devtron-public-asset.s3.us-east-2.amazonaws.com/plugins/Custom-script-Container-image.png)
106+
107+
| Field name | Required/Optional | Field description |
108+
| --- | --- | --- |
109+
| Task name | Required | A relevant name for the task |
110+
| Description | Optional | A descriptive message for the task |
111+
| Task type | Optional | Container image |
112+
| Input variables | Optional | <ul><li>**Variable name**: Alphanumeric chars and (_) only</li><li>**Source or input value**: The variable's value can be global, output from the previous task, or a custom value <br>Accepted data types include: STRING \| BOOL \| NUMBER \| DATE</li><li>**Description**: Relevant message to describe the variable</li></ul> | The input variables will be available as env variables |
113+
| Trigger/Skip condition | Optional | A conditional statement to execute or skip the task |
114+
| Container image | Required | Select an image from the drop-down list or enter a custom value in the format `<image>:<tag>` |
115+
| Mount custom code | Optional | Enable to mount the custom code in the container. Enter the script in the box below. <ul><li>Mount above code at (required): Path where the code should be mounted</li></ul> |
116+
| Command | Optional | The command to be executed inside the container |
117+
| Args | Optional | The arguments to be passed to the command mentioned in the previous field |
118+
| Port mapping | Optional | The port number on which the container listens. The port number exposes the container to outside services |
119+
| Mount code to container | Optional | Mounts the source code inside the container. Default is "No". If set to "Yes", enter the path |
120+
| Mount directory from host | Optional | Mount any directory from the host into the container. This can be used to mount code or even output directories |
121+
| Output directory path | Optional | Directory path for the script output files such as logs, errors, etc. |
122+
123+
* Select **Update Pipeline**.
124+
125+
## What's next
126+
127+
Trigger the [CI pipeline](../../deploying-application/triggering-ci.md)

0 commit comments

Comments
 (0)