This repositry contains inforamtion regarding setting up a continuous integration pipeline with Jenkins, done as part of DevOps training at Sparta Global.
- Jenkins installed or available on a server accesible online
- To have it installed on host machine, there are steps available on their website
https://www.jenkins.io/download/
- An automation software, written in Java. Its principle use is with continuous integration
- This enables projects to be continuously built and tested
- Thus overall software delivery is faster and can enables working with testing and deployment software
- It uses the pipeline-as-a-code concept, enabling automation
Creating a project
- Click on
New item
- Enter descripton of project
- Discord old builds ticked normally
- Restrict builds to 2
- This will reduce the unnneccesary builds saved
- Enter github repositry under github project tickbox
- Restrict where project can be run
- Tick then fill in box with sparta-ubuntu-node
- This may have to be inserted multiple times
- Source code
- Use git per industry standard
- Copy link to repositry as ssh per git clone syntax
- Means jenkins will need verified keys
Adding SSH key to jenkins
- follow steps to generate github SSH Key(in .ssh folder)
- https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
- Once done go to repostries > add credentials > Jenkins.
- Kind is SSH username
- ID and description is dependent on contect e.g eng67max - public ID
- SSH private key is got by
cat key_name
(in .ssh folder) - Private key is generated ssh key
- Add key then select it.
- SSH public key is got by
cat key_name.public
(in .ssh folder) - This is then pasted into Github SSH keys list.
- Reselect your credentials and it should work
Build Triggers
- Github hook trigger for GITScm polling
- Go onto the specific repo on github
- Settings > webhook > add webhook
- Insert
http://jenkins.spartaglobal.academy:8080/github-webhook/
- Before github-webhook/ the URL is interchange for what server works
- Just the push event as lots of people on small server (will likely change)
- This should auto trigger the server to build your code
Build environment
- May need to provide secret files(dont for this example)
- Provide Node and npm bin folder to path
Build
- Add execute shell step
- Add below command. Will automatically listen to github and test code
cd app/
npm install
npm test
Setting email notification
- Go to office 365 connector
- Select add webhook
- Add name then follow instructions on question mark near URL box
- It may take a few commits for it to update
The code checked is code from the develop branch (not the master branch)
- Specify branch under source code management to :origin/develop
The git publisher plugin pushes the master branch once tests pass
- Additional behaviour after build
- Push only if build succeds
- Merge results
- Add branch
- Branch to push:
master
- Target remote name:
origin
- Branch to push:
What is an API
- APIs allow apps to communicate wtih each other
- Stands for Application Programming Interface
- It governs the access points for the server
Web hook
- Inverted API call
- API call = When you ask employer if you got the job
- Inverted is where you are ready to recieve a call
- Github repositry needs link to Jenkins with this concept so it knows what to send and where to - Need to configure this
Using web hook
- Jenkins will listen for git changes
- These will then be directed to a test environment