> For the complete documentation index, see [llms.txt](https://devops-maestro.gitbook.io/cicd-pipeline-using-jenkins-and-argocd/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://devops-maestro.gitbook.io/cicd-pipeline-using-jenkins-and-argocd/create-jenkins-ci-pipeline.md).

# Create Jenkins CI pipeline

Create a new Jenkins pipeline and enable the option "GitHub hook trigger for GITScm polling"

<figure><img src="/files/g6XPI32eCIxCPCGaccke" alt=""><figcaption></figcaption></figure>

In the pipeline definition, set the SCM as Git and paste the repository URL. The branch should be set as "main"

<figure><img src="/files/DgYLP34S0ktT95BmiAk3" alt=""><figcaption></figcaption></figure>

The path to the script for Jenkinsfile must be set to *spring-boot-app/JenkinsFile* as this is the place where the Jenkinsfile is stored. Then click on Save to create the pipeline.

<figure><img src="/files/Rvn5xaqtH01THgsXr3Wv" alt=""><figcaption></figcaption></figure>

### JenkinsFile for the CI pipeline

The Jenkinsfile to create the CI pipeline looks like this:

```groovy
pipeline {
  agent {
  // Setup a Docker agent to run the Jenkins job
    docker {
      image 'abhishekf5/maven-abhishek-docker-agent:v1'
      args '--user root -v /var/run/docker.sock:/var/run/docker.sock' // mount Docker socket to access the host's Docker daemon
    }
  }
  stages {
    stage('Checkout') {
      steps {
        echo "Cloning the code"
        git url:"https://github.com/devops-maestro17/java-cicd-pipeline.git", branch: "main"
      }
    }
    stage('Build and Test') {
      steps {
        sh 'ls -ltr'
        // build the project and create a JAR file
        sh 'cd spring-boot-app && mvn clean package'
      }
    }
    stage('Static Code Analysis') {
      environment {
        SONAR_URL = //URL for SonarQube server
      }
      steps {
        withCredentials([string(credentialsId: 'sonarqube', variable: 'SONAR_AUTH_TOKEN')]) {
          sh 'cd spring-boot-app && mvn sonar:sonar -Dsonar.login=$SONAR_AUTH_TOKEN -Dsonar.host.url=${SONAR_URL}'
        }
      }
    }
    stage('Build and Push Docker Image') {
      environment {
        DOCKER_IMAGE = "containerizeops/java-app-cicd:${BUILD_NUMBER}"
        REGISTRY_CREDENTIALS = credentials('docker-cred')
      }
      steps {
        script {
            sh 'cd spring-boot-app && docker build -t ${DOCKER_IMAGE} .'
            def dockerImage = docker.image("${DOCKER_IMAGE}")
            docker.withRegistry('https://index.docker.io/v1/', "docker-cred") {
                dockerImage.push()
            }
        }
      }
    }
    stage('Update Deployment File') {
        environment {
            GIT_REPO_NAME = "java-cicd-pipeline"
            GIT_USER_NAME = "devops-maestro17"
        }
        steps {
            withCredentials([string(credentialsId: 'github', variable: 'GITHUB_TOKEN')]) {
                sh '''
                    git config user.email "rajdeep_deogharia@outlook.com"
                    git config user.name "devops-maestro17"
                    BUILD_NUMBER=${BUILD_NUMBER}
                    sed -i "s/replaceImageTag/${BUILD_NUMBER}/g" spring-boot-app-manifests/deployment.yml
                    git add spring-boot-app-manifests/deployment.yml
                    git commit -m "Update deployment image to version ${BUILD_NUMBER}"
                    git push https://${GITHUB_TOKEN}@github.com/${GIT_USER_NAME}/${GIT_REPO_NAME} HEAD:main
                '''
            }
        }
    }
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://devops-maestro.gitbook.io/cicd-pipeline-using-jenkins-and-argocd/create-jenkins-ci-pipeline.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
