yalegria / devops-git-actions

0 stars 0 forks source link

How to Set Up a Jenkins Pipeline #18

Closed Voxelghiest closed 2 years ago

Voxelghiest commented 2 years ago

Creating a Jenkins Pipeline

This is broken up into two steps for clarity: Setting up your repo for Jenkins, and actually creating the Jenkins project.

Setting Up Your Repo

Jenkins pipelines are stored in what is called a Jenkinsfile at the root of your repo. This file contains all the instructions for your various pipelines, similar to how GitHub actions are stored in a file with your repo. Here's how to set up a simple pipeline file:

  1. Create a file at the root of the repo called "Jenkinsfile" (no file extension).
  2. Open the file and copy in the following code:
    pipeline {
    agent any
    stages {
        stage('Test') {
            steps {
                sh 'echo "Hello World"'
            }
        }
    }
    }
  3. Once the Jenkinsfile has been committed to your remote repo, you can proceed with setting up the project in Jenkins.

Creating Your Jenkins Project

  1. Install Jenkins on your computer and start up the Jenkins server (See #17).
  2. From the Dashboard, select "New Item," and give your pipeline a name. Choose the "Multibranch Pipeline" option if using a GitHub repo as the source. Then select "Okay," which creates the new item.
  3. You will be brought to the configuration panel for your new item. Scroll down to "Branch Sources" and select
    "Add source > GitHub".
  4. The next step is to add your GitHub credentials so you have full access to your repo's information. Under "Credentials," select "Add". Depending on whether you want the credentials to be scoped to your Jenkins account as a whole or to just this one project, select either "Jenkins" or the name of your project.
  5. Fill in your GitHub login information. You may have to create an appropriate GitHub Personal Access Token to use as the password. Optionally, give it a short description so you can identify it more easily later. Once you're done, select "Add" to exit the panel.
  6. Now use the dropdown menu to select your credentials. Fill in the https URL of the repo as well.
  7. Finally, go to the very bottom of the entire configuration window and select "Save" to confirm your configuration changes. You can return to this panel anytime to update settings as needed.