Continuous Integration Providers
In this chapter we will discuss the integration providers supported by Spinnaker. By the end of this chapter, you should be able to explain.
- Supported Integration Providers
- Set up a spinnaker instance on Jenkins
As we mentioned in the earlier chapters, Continuous Delivery is the ability to deploy the code in the test environments and subsequently to the production environment. It is an activity carried out after Continuous Integration. The entire deployment and delivery process is automated to achieve this. This delivery process is not just about building the code and deploying it in any environment, it is about carrying out a bunch of tasks, like code scans, performing different kinds of automated testing etc. TasksTo tasks are automated using different tools and for any CI-CD system to work flawlessly, it needs to be connected to a bunch of these tools. These tools are integrated with the CD tool to achieve the required flow for continuous delivery.
Spinnaker can listen to events, and collect artifacts produced by builds in external Continuous Integration (CI) systems. These events can trigger Pipelines, and the artifacts can be used by Spinnaker’s image bakery to produce machine images. It can trigger automated testing activities on the deployed artifacts and gather results to decide on whether or not the code can be promoted to the next environment. Spinnaker integrates a variety of tools to accomplish this.
In this chapter we will focus on a few of such tools that can integrate with Spinnaker and can run flawlessly to enable a successful CD system.
Spinnaker supports several CI systems that can be enabled and run independently of one-another, few of them are.
- AWS CodeBuild
- Google Cloud Build
- Travis CI
The following steps will include integrating Jenkins with Spinnaker, and building a job in Jenkins for which we will receive a triggered alarm in Spinnaker. We have also included a Jenkins installation guide here.
We have built Jenkins with Centos as the base image and have used the LTS version of Jenkins.
- Run the following command to install Jenkins.sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.reposudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.keysudo yum install jenkins
- Once the installation is complete, run the following command to start the Jenkins service.sudo service jenkins start/stop/restartsudo chkconfig jenkins on
Note: Jenkins uses JAVA, so make sure that the Openthat Open JAVA Development kit is already installed.
- The following screen will appear once Jenkins has been configured with the Username and Password.
- Select create new jobs from the home screen, which will take you to the next screen, where you can select from a variety of options based on your project. Refer to the image below.
- Pipeline will be used in this example to orchestrate long-running activities that can span multiple build agents.
- Select pipeline and enter a name for the same my-first-pipeline-01, once done the following screen will appear.
- The above screen has 4 options are:
- Build Triggers
- Advanced Project Options
From describing your Pipeline to Pipeline script definition, you can customize it accordingly. Once done you can save and apply. The following screen will appear.
- In the stage view, in the above screenshot it says “No data available. This Pipeline has not yet run.” It’s an empty stage, however we will integrate Jenkins with Spinnaker before running the pipeline.
- A running Jenkins Master at version 1.x - 2.x, reachable at a URL ($BASEURL) from the Spinnaker deployment provider.
- If Jenkins is secured, a username/password ($USERNAME/$PASSWORD) pair can use HTTP Basic Auth to authenticate against it. This username/password can be the same as the one you used to set up Jenkins. Initially when you set up Jenkins it will prompt you for administrator password which is usually stored in /var/lib/jenkins/secrets/initialAdminPassword, and then you get an option to configure username/password. In our example we have used the same.
- Ensure that Jenkins is enabled within Halyard. Hence login to spin-halyard and type the below command:hal config ci jenkins enable
Follow the steps below to start the integrations:
- Add a JenkinsAdd Jenkins master named my-jenkins-master (an arbitrary, human-readable name), to our list of Jenkins masters.echo $PASSWORD | hal config ci jenkins master add my-jenkins-master \--address $BASEURL \--username $USERNAME \--password # password will be read from STDIN to avoid appearing# in your .bash_history
- Use the following command for Re-deploy Spinnaker to apply the changes.hal deploy apply
- You can also configure Jenkins and Spinnaker for CSRF protection.
- Use the following command to enable csrf flag in Halyard pod.hal config ci jenkins master edit my-jenkins-master --csrf trueOnce done invoke, hal deploy apply
Select Prevent Cross-Site Request Forgery exploits under Manage Jenkins > Configure Global Security. This option is usually already selected. Select Default Crumb Issuer under Crumb Algorithm, as shown below.
- Create a Pipeline Trigger. After you have logged into your Spinnaker UI follow the below steps. We have created a test1 application, for which we will create a Pipeline as shown below.
- Once you select the application you will get an option to configure a Pipeline as shown below.
- Click on configure a new pipeline. A dialogue box will appear, asking for the Pipeline Name; in this example, JenkinsPipeline was used as the Pipeline Name, as shown below.
- Once you have created the Pipeline you will be directed to the Pipeline configuration page where you can configure Automated Triggers using Jenkins that was integrated earlier. Refer to the image below.
- In the Automated Trigger window select Add Trigger and for option Type select Jenkins for the Master option which was created earlier in Spinnaker in the example which is my-jenkins-master.
- For the Job option select my-first-pipeline-01 which was created in Jenkins. The parameters for Master and Job will be available automatically once you select Jenkins in the Type option, provided you have configured Jenkins correctly. Refer to the image below.
- After you have selected the parameters in Automated Trigger, click Save Changes.Then navigate to the application test1 page. You will see the Jenkins Pipeline has been created with Trigger: enabled.
- Now, in the Jenkins console, select the job named my-first-pipeline-01 that you created earlier. You will be redirected to the detailed job page, there on the left hand corner click the option build now. The message "The Pipeline has run successfully" will appear. Refer to the image below.
- Navigate back to Spinnaker you will get a screen stating TRIGGERED BUILD.