Pre-Build/Post-Build tasks

The CI pipeline includes Pre and Post-build steps to validate and introduce checkpoints in the build process.

The pre/post plugins allow you to execute some standard tasks, such as Code analysis, Load testing, Security scanning, and so on. You can build custom pre/post tasks or use one from the standard preset plugins provided by Devtron.

Before you begin

Create a CI build pipeline if you haven't done that already!

Configuring Pre/Post-build stages

Each Pre/Post-build stage is executed as a series of events called tasks and includes custom scripts. 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.

The tasks will run following the execution order.

The tasks may be re-arranged by using drag-and-drop; however, the order of passing the variables must be followed.

Creating a task

  1. Go to Applications and select your application from the Devtron Apps tabs.

  2. From the App Configuration tab select Workflow Editor.

  3. Select the build pipeline for editing the stages.

Devtron CI pipeline includes the following build stages:

  • Pre-build stage: The tasks in this stage run before the image is built.

  • Build stage: In this stage, the build is triggered from the source code that you provide.

  • Post-build stage: The tasks in this stage are triggered once the build is complete.

You can create a task either by selecting one of the available preset plugins or by creating a custom script.

Preset plugins | Execute custom script

Preset plugins

Prerequisite: Set up Sonarqube, or get the API keys from an admin.

The example shows a Post-build stage with a task created using a preset plugin - Sonarqube.

  1. On the Edit build pipeline screen, select the Post-build stage (or Pre-build).

  2. Select + Add task.

  3. Select Sonarqube from PRESET PLUGINS.

Input Variables

Select Update Pipeline.

Execute custom script

  1. On the Edit build pipeline screen, select the Pre-build stage.

  2. Select + Add task.

  3. Select Execute custom script.

The task type of the custom script may be a Shell or a Container image.

Custom script - Shell

  • Select the Task type as Shell.

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". The task triggers only if the database name matches "mysql". If the trigger condition fails, this Pre-build task will be skipped and the build process will start. The variable DB_NAME is declared as an output variable that will be available as an input variable for the next task. The task fails if DB_NAME is not equal to "mysql".

  • Select Update Pipeline.

Here is a screenshot with the failure message from the task:

Custom script - Container image

  • Select the Task type as Container image.

This example creates a Pre-build task from a container image. The output variable from the previous task is available as an input variable.

  • Select Update Pipeline.

What's next

Trigger the CI pipeline

Last updated