Understanding OneDev Pipeline
Tags: devops
Published: 2022-04-11 09:57:41

[OneDev](https://onedev.io) introduced pipeline concept since 7.0. In short, a pipeline is an execution of job dependency graph. It can be created by running any job in the graph, either manually or automatically via job triggers.

# Create a Pipeline

Login to [OneDev demo site](https://code.onedev.io/login) with account _demo/demo_, switch to [CI spec definition page](https://code.onedev.io/projects/369/blob/master/.onedev-buildspec.yml) of the demo project, you will see job definitions like below:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v16vx1176yiflrzwtnm4.png)

Here we define a _test_ job to compile and test our app, and then publish compiled app as artifacts so that it can be deployed later. The _deploy_ job retrieves published app via dependency to the _test_ job, and gets it deployed as shown below:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qdyqlmpcew0xv4tp1h9v.png)

Now run the _test_ job, you will be brought to the page showing generated build. A pipeline will also be created as the job dependency graph is executed as result of running the _test_ job. The pipeline tab shows the created pipeline current build is part of:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sjww98kyem72vaj24nu0.png)

**NOTE**: pipeline tab is only visible to users with code read permission

# Pipeline Characteristics

Pipeline has two characteristics:

1. Builds fired manually from pipeline view, or by other builds in the pipeline via job triggers, dependencies and post-build actions belong to same pipeline.
1. For a particular pipeline, only one build will be generated from same job and parameter. If no parameter is defined for the job, it can only be triggered once then.

To demonstrate, run the _deploy_ job from above pipeline, from the build log you will see that it is actually deploying the app published by existing test build in that pipeline:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qn0qhzgq937euzsu715j.png)

Also pipeline tab of the deploy build shows that it belongs to same pipeline as test build above:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1b0zp7s2nd2jcvf150jt.png)

If we run _deploy_ job again in this pipeline, OneDev will indicate that the build is already fired:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v0sa0j6cb8zrjsqns4xc.png)

However if you run _deploy_ job from outside of the pipeline, a new pipeline will be created and new builds for _test_ and _deploy_ job will be generated for the new pipeline. Again, let’s check this in action. Switch to [commits page](https://code.onedev.io/projects/369/commits) to run _deploy_ job for some commit with existing test build:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l20yl4e0mue3xuyb8ouv.png)

A new deploy build will be generated, as well as a new pipeline. Switch to pipeline tab of the new build, you will see that new test build also gets generated in regardless of existing test builds for the commit.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hintq9nq1balwmeaqaj.png)

# Pipeline Automation

Pipeline can be created automatically if a job is set to fire upon certain event. For instance, in [CI spec](https://code.onedev.io/projects/370/blob/master/.onedev-buildspec.yml) of this demo project, we set job _test_ to trigger automatically when there are new commits in master branch:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3es07pzacn5j4usck0dz.png)

[Make some changes to app.txt](https://code.onedev.io/projects/369/blob/master/app.txt?mode=edit) and save the file, you will see that _test_ job is running:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q5o3oxgnhsxwbxsn09n5.png)

Click the running test build and you will be brought to build detail page, from which created pipeline can be accessed.

Now assume you want to deploy the app automatically when _test_ job is successful. To do it, add a trigger to fire the _deploy_ job when dependency jobs finished like below:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wqizc9n1wp3lbuna5tiu.png)

To test it in action, [make some changes to app.txt in this project](https://code.onedev.io/projects/370/blob/master/app.txt?mode=edit), save the file, open created pipeline and wait to see _deploy_ job running automatically after test job is successful:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yjdlpsml7x9opa0oam16.png)

Alternatively, you may also configure a branch update trigger for _deploy_ job. In that case, both _deploy_ job and _test_ job will be fired upon changing file, but _deploy_ job will wait for _test_ job to complete before running as shown in the pipeline:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/idxigvzd7kda2n6sajh5.png)

Now you should get an idea how pipeline works in OneDev. Any questions, please post at our [issue tracker](https://code.onedev.io/projects/160/issues?query=%22State%22+is+%22Open%22).

Thanks for watching!