Basic diagram on the basics of Jenkins
So, what is the point of a pipeline:
It lets you run different items based on the outcomes of other items see! So let's make one:
- Click
New Item
- Give it a name and click
Freestyle project
- Go down and add some build triggers, just make sure it can pass
- Generate some keys, add the public key to the repository you want jenkins to access and add the private key to jenkins itself. A reminder of how to do that in this repo
- Go to Post-Build Actions and type in the name of a project you'd like to run after this build has completed. You also have the option to trigger if build is stable, unstable or if it has failed
- Build your project and check the console to see what it has done!
a.k.a. testing and merging in Jenkins
For this we are going to need two jenkins items, one for running the test on our dev branch and one for merging the dev branch in to main if the tests pass
So, let's create our test item:
- Click
New Item
- Give it a name and click
Freestyle project
- Tick GitHub project and put in the HTTPS link to your repo
- Check "Restrict where this project can be run" and enter in your Label Expression
- Generate some keys, add the public key to the repository you want jenkins to access and add the private key to jenkins itself. A reminder of how to do that in this repo
- Then in Source Code Management select "Git" and enter in your SSH repo url and add your private key
- In your branches to build add in
*/main
and*/dev
as your branches to watch - In "Build Triggers" check "GitHub hook trigger for GITScm polling"
- In "Build Environment" check "Provide Node & npm bin/ folder to PATH" and fill in respectively
- Next fill out your "Build" with some shell commands:
cd app npm install npm test
- In "Post Build Actions" you are going to want to link it to your merging item (which we will create next). If you already know what you want to call it post it in here, or else just come back later
- Click
New Item
- Give it a name and click
Freestyle project
- Tick GitHub project and put in the HTTPS link to your repo
- Check "Restrict where this project can be run" and enter in your Label Expression
- Generate some keys, add the public key to the repository you want jenkins to access and add the private key to jenkins itself. A reminder of how to do that in this repo
- Then in Source Code Management select "Git" and enter in your SSH repo url and add your private key
- In additional behaviours add a merge before build and merge origin in to main
- Some shell commands to merge the branches
git checkout main git merge origin/dev
- In "Post Build Actions" setup a "Git Publisher" and set it to "Push Only If Build Succeeds" and branches you want to push
main
toorigin