Accelerate the Software Development Lifecycle with Jenkins
1.Setup the Github Repository
To begin with, you will need to create an account on Github. (You can skip the registration part if you already have an account). Please ensure that you push the application's source code to a branch called "master". Once the code is in master, you can create another branch (from master) for your tests called "develop".
1. To create the Github account, head to the sign up page and fill out the form to sign up for a new account. (Only applicable if you don't have an account already. If you have one, please use it).
2. Once logged in, create a new repo at https://github.com/new. Ensure that you provide a meaningful name and then create it.
3. To access this repo you will need to generate an access token. Go to https://github.com/settings/tokens. Select "repo" permissions only and create it. Ensure that you save your Github token since it will be used in the future.
4. Clone your Github repository and configure how your name will be displayed in every commit.
- git clone https://<username>:<token>@github.com/<your-github-username>/<your-repo-name>.git ~/code/my-repo
- cd ~/code/my-repo
- git config --global user.email "<my-email-id>@example.com"
- git config --global user.name "<your-name> <last-name>"
Please ensure that you replace the placeholders surrounded by <>
with real values.
5. Locate the main.go file (attached as an asset) and ensure that you create a new file with the same name and the same content. Once copied, it's time to create the "master" and "develop" branches.
- cd ~/code/my-repo
- nano main.go # Copy the content of the main.go asset. Then, save it.
- git add main.go && git commit -m "First commit" && git push -u origin master # Creates master branch
- git checkout -b develop && git push -u origin develop # Creates develop branch
6. Ensure that you can see both branches in your Github repo.
2.Create a MultiBranch Pipeline and Integrate it with Github
The next step is to create Multibranch Pipeline in Jenkins. The Pipeline should read the steps from a Jenkinsfile hosted in your Github repo.
Something to keep in mind: Due to security policies in the company, we are not allowed to configure Github webhooks. Therefore, Jenkins polling should be used instead.
1. Log in to your Jenkins instance and create a new pipeline by clicking on "New Item". Ensure that you provide a meaningful name and that the type is "Multibranch Pipeline". Once done, click ok.
2. To integrate this Pipeline with Jenkins, we need to configure the GitHub token that you created for authentication. Locate "Branch Sources", then select "Github" as your source. You will need to create a new "Credential" to be able to authenticate against your Github account.
3. Add your Github username and token as well as your repo URL to complete the Github integration. Jenkins offers a "Validation" button to double-check that everything is working as expected.
4. Navigate to "Behaviors" and ensure that you only have one behavior. This "behavior" should be "Discover Branches/Strategy/All Branches".
5. To conclude with the Pipeline configuration, head to the "Build Configuration" section and ensure that the "Script Path" is "Jenkinsfile". Also, ensure that you set the scanning interval to 3 minutes. Lastly, save the changes.
Before building the application, we need to have an installation of "Golang" totally functional. Please go on and download/configure Golang in Jenkins to be able to build and test the application.
1. Go to the Jenkins plugin manager at https://<your-jenkins-url>/pluginManager
. Locate and install the Golang Plugin. You should see green ticks at the end of the installation to ensure that everything worked as expected.
2. Head to the Jenkins Global Tool Configuration at https://<your-jenkins-url>/configureTools
to tweak the Go plugin installation. First off, locate the "Go" section, add a new "Go Installation" and delete the default installer.
3. Add a new installer of type "Run Shell Command". The script that will be run by the installer is attached as an asset with the name "go-plugin.txt". Ensure that the "Tool Home" is set to "./go".
Labels: SDLC with Jenkins
0 Comments:
Post a Comment
Note: only a member of this blog may post a comment.
<< Home