# Part 7: Control Jenkins Pipeline through GitHub

### Jenkins CI/CD Series

| Part | Article |
| --- | --- |
| 1 | [Install Jenkins with Docker](https://ask-abhi.com/part-1-install-jenkins-with-docker) |
| 2 | [Creating Your First Jenkins Pipeline](https://ask-abhi.com/part-2-creating-your-first-jenkins-pipeline) |
| 3 | [Jenkins SSH Remote Execution](https://ask-abhi.com/part-3-jenkins-ssh-remote-execution) |
| 4 | [Automating MySQL Backup to AWS S3](https://ask-abhi.com/part-4-automating-mysql-backup-to-aws-s3) |
| 5 | [Making Jenkins Automation Scalable](https://ask-abhi.com/part-5-making-jenkins-automation-scalable) |
| 6 | [Running Ansible from Jenkins](https://ask-abhi.com/part-6-running-ansible-from-jenkins) |
| 7 | [Jenkins Pipeline from GitHub](https://ask-abhi.com/part-7-control-jenkins-pipeline-through-github) |
| 8 | [Multibranch Pipelines](https://ask-abhi.com/part-8-multibranch-pipelines) |
| 9 | [Parameterized Pipelines](https://ask-abhi.com/part-9-parameterized-pipelines) |
| 10 | [Environment Variables in Pipelines](https://ask-abhi.com/part-10-environment-variables-in-pipelines) |

* * *

### Goal

Configure Jenkins to use a **Jenkinsfile stored in a GitHub repository**, enabling pipelines to be version-controlled, automatically updated, and executed directly from source code.

* * *

### Purpose

The purpose of this part is to introduce **Pipeline as Code using GitHub**, which is a core DevOps practice.

By the end of this setup, you will:

*   Store Jenkins pipeline logic inside GitHub
    
*   Configure Jenkins to pull pipeline code from SCM
    
*   Automatically detect changes in the repository
    
*   Build pipelines that are **version-controlled and reusable**
    

This approach ensures that your CI/CD pipelines are:

*   **Traceable** (tracked via Git commits)
    
*   **Collaborative** (teams can contribute)
    
*   **Consistent** (same pipeline across environments)
    

* * *

### Prerequisites

Before starting this part, ensure you have:

*   Ready to use `Host` and the `directory` structure to run `Dockerfiles` and `docker-compose.yml` (Refer to [Part 1](https://ask-abhi.com/part-1-install-jenkins-with-docker))
    
*   A GitHub account
    
*   Access to a [demo-app](https://github.com/abhinandan-chougule/demo-app-java-maven.git) repository (fork or create)
    

* * *

### Step-by-step implementation

*   **Jenkinsfile is placed at the location below in the repo, and will be used**
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/3b626a02-4ebd-4066-b5d2-a23966698191.png align="center")

*   **Create a new Job** `maven-github-pipeline`
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/1d4981fa-062c-4281-9def-2ea1c3f5b6fe.png align="center")

*   **Select options as below**
    

**Definition**: `Pipeline script from SCM`  
**SCM**: `Git`  
**Repository URL :** `Forked repo HTTP URL`  
**Branch Specifier (blank for 'any')**: `*/main`  
**Script** **Path**: `jenkins/Jenkinsfile`

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/10b6f381-0920-45b2-aaca-d7be1b29edb3.png align="center")

**Build now**

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/73863c38-5ca1-4cca-a4ab-f8a6402d0575.png align="center")

*   **Go through the console output logs**
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/652c7c4b-bfb9-49dc-94cf-537bb9304cb7.png align="center")

*   **Build now one more time, and go to Jobs Console output and compare**
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/3604f007-0b12-41cd-9ece-d64a2643a7fb.png align="center")

<mark class="bg-yellow-200 dark:bg-yellow-500/30">This is not cloning the repo again; instead, it's checking if there are any latest commits and changes</mark>

### **Done!!!**

* * *

### Conclusion

In this part, you successfully moved your Jenkins pipeline to **GitHub**, adopting the powerful concept of **Pipeline as Code**.

You have:

*   ***Connected Jenkins to a GitHub repository***
    
*   ***Configured pipeline jobs to fetch the Jenkinsfile from SCM***
    
*   ***Executed builds directly from the repository code***
    
*   ***Observed how Jenkins detects changes without re-cloning***
    
*   ***Introduced version-controlled CI/CD workflows***
    

This is a critical step toward **modern DevOps practices**, where pipelines are no longer managed manually in Jenkins but are fully integrated with source control systems.

With this setup, your pipeline becomes:

*   **Scalable**
    
*   **Maintainable**
    
*   **Production-ready**
    

* * *

### 🔗 Continue the Series

⬅️ **Previous Article:** [Part 6 Running Ansible from Jenkins](https://ask-abhi.com/part-6-running-ansible-from-jenkins)  
➡️ **Next Article:** [Part 8 Multibranch Pipelines](https://ask-abhi.com/part-8-multibranch-pipelines)

* * *

⭐ If you found this article useful, follow **https://ask-abhi.com** for more DevOps tutorials.

* * *
