Loading

Quipoin Menu

Learn • Practice • Grow

jenkins / Pipeline as Code
tutorial

Pipeline as Code

Pipeline as Code means storing your Jenkinsfile in your source control repository alongside your application code. This is a best practice that brings version control, code review, and traceability to your CI/CD pipelines.

Why Pipeline as Code?

  • Version control: Changes to pipeline are reviewed via pull requests.
  • Auditability: Know who changed what and when.
  • Reusability: Share Jenkinsfiles across projects.
  • Consistency: Same pipeline logic for all branches.

Creating a Jenkinsfile

In your Git repository, create a file named Jenkinsfile (no extension). Write your pipeline code inside. Example:
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
}

Configuring a Pipeline Job to Use Jenkinsfile from SCM

1. Create a new "Pipeline" job.
2. Under "Pipeline", choose "Pipeline script from SCM".
3. Select SCM (e.g., Git).
4. Enter repository URL and credentials.
5. Specify branch (e.g., main).
6. Set "Script Path" to Jenkinsfile (or custom path).
7. Save. Jenkins will load the pipeline from the repo.

Multibranch Pipelines

For projects with multiple branches, use "Multibranch Pipeline". Jenkins automatically discovers branches and creates a pipeline for each branch that contains a Jenkinsfile. It also shows branch statuses on the UI.

Shared Libraries (Revisited)

Combine pipeline as code with shared libraries to avoid repeating boilerplate. Store common pipeline logic in a separate repo and load it in Jenkinsfiles.

Best Practices

  • Keep Jenkinsfile minimal – delegate complex steps to shared libraries.
  • Use environment for configuration, not hard‑coded values.
  • Test Jenkinsfile changes using a test branch or PR builds.
  • Use options { timeout } to avoid hung builds.


Two Minute Drill
  • Store Jenkinsfile in Git with application code.
  • Configure pipeline job to use "Pipeline script from SCM".
  • Multibranch pipelines automatically handle branches.
  • Use shared libraries to reduce duplication.

Need more clarification?

Drop us an email at career@quipoinfotech.com