Skip to content Skip to sidebar Skip to footer

Integrate Protractor With Jenkins for Continuous

Contents

  • 1 Overview of Jenkins
    • 1.1 Key features
  • 2 Continuous integration
  • 3 Install standalone Jenkins
    • 3.1 Download and install Jenkins
    • 3.2 Unlock Jenkins
    • 3.3 Configure Jenkins
    • 3.4 Verify Git plugin is installed
  • 4 Jenkins global Git settings
  • 5 Create a Jenkins project
    • 5.1 Create a new item
    • 5.2 Project settings
    • 5.3 Trigger Jenkins to build
    • 5.4 Monitor a project's build status
    • 5.5 Modify an existing project's settings
  • 6 Advanced features
    • 6.1 Monitor builds with CatLight
    • 6.2 Use Jenkins from the command line
    • 6.3 How to create and configure users and assign them roles and access to projects
      • 6.3.1 Users
      • 6.3.2 Roles
      • 6.3.3 Create some roles
      • 6.3.4 Assign roles to users
      • 6.3.5 Create a project
    • 6.4 Useful configuration options
    • 6.5 Automating Java builds with Maven
    • 6.6 Change Jenkins' home directory
  • 7 References
  • 8 What links here

Overview of Jenkins

Jenkins hero image.png

provides an easy-to-use "continuous integration" automation system, making it easier for developers to integrate changes to a project, and making it easier for users to obtain a fresh build of a system after changes. An automated, continuous build removes the amount of time developers must spend integrating their work with an existing code base.

Jenkins is an easy-to-use open source automation server which enables developers to automate development lifecycle processes of all kinds, including building, documenting, testing, packaging, staging, deploying, analyzing and much more.

Jenkins is being widely used in areas of Continuous Integration, Continuous Delivery, DevOps, and other areas. It is not only used for software - the same automation techniques can be applied in other areas like Hardware Engineering, Embedded Systems, BioTech, etc.

Key features

  • open source
  • written in Java, making it platform independent
  • can be easily deployed on cloud service platforms, like Microsoft Azure
  • supports a 3rd-party plugin marketplace for adding extra functionality and integrations with other software tools
  • used for continuous integration, continuous deployment, continuous delivery; in other words, automation of many mundane tasks.

Automation tasks could be for any type of software product:

  • apps
  • exe files
  • web sites
  • basically, any task that can be performed from the command line can be automated in Jenkins

Continuous integration

A high-level view of continuous integration

In a typical continuous integration / continuous deployment workflow:

As soon as any code is pushed to a shared repository, such as Git...

  • a build is automatically triggered using latest code from the repository
  • notifications are sent out via email or other channels when the build is triggered, and when it completes
  • allows easy monitoring of status and attribution of build fails to specific commits and specific team members

After the build process is complete, Jenkins can:

  • automatically run tests to validate the build
  • automatically deploy or deliver the build

Jenkins can send notification of the status of building/testing/deployment/delivery at the beginning and end of each stage

Install standalone Jenkins

In this exercise, we will install Jenkins on your local computer with only one user - you! This will create a local copy of Jenkins in isolation on your computer. This will work fine for our needs in this course.

Note that in a production environment, we would rather do one Jenkins installation for an entire team by installing it on a shared server that all team members can access via the web.

Download and install Jenkins

Download and install the latest stable installer for your system from https://jenkins.io

  1. follow installer instructions until complete... you now have Jenkins!

Unlock Jenkins

Jenkins administration is locked by default. You have to retrieve the password and unlock it.

The unlock screen of the Jenkins web interface

  1. the web interface will notify you of the path to a file that contains an administrator password... navigate to that file on the command line
  2. give yourself permission to everything in that directory if necessary to open it
    • e.g., use the UNIX sudo command, such as 'sudo chmod -R a+rwx secrets'
    • you will be asked for the admin password on your machine... enter it
  3. paste the password you copy from that file into the web interface to give yourself admin permissions in Jenkins
  4. Jenkins is now available locally from a web browser on localhost at the port specified by the installer, typically 8080
    • usually http://localhost:8080
  5. Jenkins creates a hidden .jenkins folder in your user account with all configuration options and plugins in there
    • maybe don't touch that right now!

Configure Jenkins

Installing the default plugins through Jenkins web interface

  1. go to http://localhost:8080, if you're not already there in a web browser
  2. enter username 'admin' and the password you saved earlier, if asked
  3. select plugins to install - start with suggested plugins

Verify Git plugin is installed

The Git plugin for Jenkins allows changes to a Git repository to trigger actions within Jenkins.

  • this plugin is installed by default with most Jenkins distributions
  • check by going to Manage Jenkins -> Manage Plugins, and click the 'Installed' tab to see whether 'Git plugin' is listed
  • if not, install it and then restart Jenkins by going to http://localhost:8080/restart

Jenkins global Git settings

View git config values

Enter git config values into Jenkins Configure System settings

Create some basic Git integration settings within Jenkins. These will apply to all projects.

From your Jenkins dashboard...

  1. Click 'Manage Jenkins'
  2. Click 'Configure System'
  3. Under the 'Git Plugin' options, enter your Git user.name and user.email values
    • these should be consistent with your Git config settings... if you haven't set your user.name and user.email settings in Git, do so!
    • to view the value of these config settings in Git, try the following command on the command-line: 'git config --get user.name' and 'git config --get user.email'

Create a Jenkins project

For each individual project in Jenkins, you can set how it should integrate with Git.

New freestyle Jenkins project

General settings for a Jenkins project

Source control management settings for a Jenkins project

Build trigger settings for a Jenkins project

Some nonsense settings for a Jenkins project... yours will actually build something!

Don't forget to save settings!

Create a new item

From the Jenkins dashboard...

  1. clicking 'New Item'
  2. enter a name for your project
  3. select "Freestyle project" as the project type
  4. submit

This takes you to a project settings screen. Continue as per below.

Project settings

General settings:

  1. Check the 'GitHub project' checkbox
  2. enter the GitHub project url
    • this is the main repository URL on GitHub, not including any specific trunk/branch in the URL
    • e.g. https://github.com/nyu-software-engineering/test-repository/
  3. Specify 'Source Code Management' settings
    • Enter the repository URL - this is the link to a *.git repository that GitHub provides when you click to 'Clone or download" button on a repository
    • Select the GitHub account to use in the 'Credentials' drop-down list - your account should automatically appear
    • Specify the branches to build... leave this as 'master', unless you prefer to track and build from another branch
  4. leave 'Repository browser' as 'Auto'
  5. Under 'Build Triggers', check 'Poll SCM' so Jenkins continuously polls the repository for changes
    • specify a schedule that indicates how frequently to poll the repository
    • e.g,. 'H/15 * * * *' to poll every 15 minutes... see the Jenkins schedule help for more on this syntax
  6. Under 'Build', select 'Execute shell'
    • enter the command-line commands you would like to execute once Jenkins discovers that the repository has changed
    • this is dependent upon the nature of your project
    • could include commands to build, test, upload code to a staging or production server, etc.
    • to start try entering commands build or execute the code from the repository
    • you can assume the repository code has been pulled to the working directory within which Jenkins is running the shell script
  7. Save these settings

Trigger Jenkins to build

  1. Commit a change to the GitHub repository
  2. Go to Jenkins' dashboard view
  3. Check for activity in the "Build queue" area on the dashboard
    • Note that how quickly Jenkins discovers the change depends on the polling schedule you indicated in the project settings
    • If you're impatient, you can manually schedule an immediate build of any project by clicking an icon at the very right of the project listing, or by clicking into a Project and then clicking the 'Build Now' link

Monitor a project's build status

Jenkins project build history

A project's most recent build results are visible from the Jenkins dashboard - the status icon shows you a color that represents the 'weather', which is a fancy way of saying the average of the last 5 builds.

For a full history of individual build successes and failures, from the Jenkins dashboard...

  1. click into a project
  2. view the status in the latest Build History area
  3. click on one of the status icons in the Build History to view the console log of the build

Modify an existing project's settings

  1. Click into the project from the Jenkins dashboard
  2. Click the 'Configure' link
  3. Adjust settings as desired

Advanced features

The following features are not necessary for the typical project in this course . Try at your own risk!

Monitor builds with CatLight

Catlight notification

Catlight is a desktop notification app for developers. It can be pointed at Jenkins to visually show you the status of any automated builds that Jenkins performs.

Catlight will notify you when a build needs your attention. It shows the current status of continuous delivery, tasks and bugs in the project and informs when attention is needed. This notification can take several forms, based on how you configure it.

  • install Catlight as standalone app - https://catlight.io
  • set it up to look at Jenkins by giving it your Jenkins URL
  • configure the notifications in settings

Use Jenkins from the command line

Configure Global Security in Jenkins web interface

Jenkins offers a .jar file that can be used to run Jenkins commands from the command line. View the official Jenkins command-line interface documentation for details.

There is no need to run Jenkins from the command-line for simple projects!

To allow this...

  1. Start Jenkins
  2. Go to web browser interface to Manage Jenkins -> Configure Global Security, and make sure 'Enable security' is checked and save
    • if you are the only user of the machine on which Jenkins is installed, you can also select the 'Anyone can do anything' option to allow all user accounts you create unlimited permissions
  3. Go to web browser: http://localhost:8080/cli to see command line reference
    • this page shows a link to download the jenkins-cli.jar file
    • save that file somewhere on your local machine
  4. Go to command line
  5. Navigate to wherever you saved the .jar file
  6. Execute the .jar file as follows: 'java -jar jenkins-cli.jar -s http://localhost:8080/ help'
  7. Enter password for admin user pass phrases (pass phrases can be set through web interface user account area)
  8. Try out a command from the command-line reference page, such as the safe-restart command
  9. If the command requires particular permissions, you can allow anyone to run any command from the 'anyone can do anything' configuration options in the web interface under Manage Jenkins ->Configure Global Security

How to create and configure users and assign them roles and access to projects

A powerful feature of Jenkins when used in a team environment is to assign specific users particular sets of privileges, known as roles. This determines who can do what within a shared Jenkins installation.

Users

  • Create two users with usernames/passwords using form in web interface
  • Users can manage their details in their own account settings area

Roles

Roles allow you to quickly assign privileges to specific users. This is useful in teamwork. To assign roles, you will first install a plugin, if it is not already installed.

  1. Install Jenkins 'Role-based Authorization Strategy' plugin in one of two ways:
    • install through web interface go to Manage Jenkins -> Manage Plugins and search for and install it
    • or... alternatively, download it and install into plugins directory in Jenkins home folder - or
  2. Restart Jenkins
    • there is a button to restart in the web interface at the very bottom of the page that shows the installation status of the plugin
    • you can always navigate to http://localhost:8080/restart manually
  3. Go to Manage Jenkins -> Configure Global Security
    • make sure 'enable security' is checked
    • in Authorization settings, check 'Role-Based Startegy" and apply and save

Now users must be given permission for everything through Manage Jenkins -> Manage and Assign Roles

  • Roles come in three types:
    1. Global roles
    2. Project roles
    3. Slave roles

Create some roles

Creating roles is a prerequisite for then assigning those roles to specific users.

  • Add a new Global role, 'employee' and select 'Read' and overall 'View' access options
  • Add a new Project role, 'developer' and assign them all permissions on projects starting with Dev, by entering Pattern Dev.* and selecting all permissions that appear
  • Add a new Project role, 'tester' and assign them all permissions on projects starting with Test, by entering Pattern Test.* and selecting all permissions that appear
  • Save changes

Assign roles to users

  • Go to Configure Jenkins -> Manage and Assign Roles -> Assign Roles
  • Add two users to the Global roles and select 'employee' as their role, and click 'Apply'
  • Add two user to the Project roles - give one as a developer role, and the other as a tester role
  • Save changes

Create a project

Creating a few projects can show you the value of the roles that you have created for various users.

  • Create a project named "Dev Project 1" and another "Test Project 1"
  • The two users will be automatically given access to their respective projects based on their patterns

Useful configuration options

General settings that may come in handy down the line.

Changing these settings is not required at the start of a small project

  1. of executors - how many jobs can be built at one time
  2. Quiet period (in seconds) - when a build is triggered, for example due to a commit to Git, how long to wait before triggering a build.. 10 seconds or more is a good idea to make sure everything is ready brefore building
  • SCM checkout retry count - how many seconds to wait before trying to set a source code repository for changes
  • Restrict project naming - allows you to force new projects to start with a certain string prefix
  • Environmental properties - can set key/value pairs available as variables from within build jobs

Job-specific configuration settings

  • Build triggers - allows builds to be triggered from scripts (URLS or API calls), after other projects, on a periodic schedule, or after source code repository commits (requires a plugin)
  • Add build step - can execute windows batch command, execute shell command, or invoke top-level Maven targets
  • Post-build actions - build another project, and other actions

In jobs list

  • Status column is gray for new jobs, blue if last build succeeded, and red otherwise.
  • Weather column shows average of last 5 builds

Automating Java builds with Maven

Jenkins works with the popular Java build automation tool, Apache Maven, natively...

  • install latest Maven from Apache
  • go to Manage Jenkins -> Configure System -> Maven Installation tab
  • add name and path to Maven installation and save
  • create a new Job and set type to be Maven project
  • set the source code management for the new project to be Git, and enter a valid Git repository URL for the project
  • set the build triggers for the project to 'poll SCM', with a schedule to check every minute, so Jenkins periodically polls the repository for changes
  • in Build settings, enter a 'Root POM' path... need to check what this is?!
  • in Build settings, set 'Goals and options' to 'clean install' to remove any build artefacts and install the build into the main repository
  • Save
  • commit some files to Git and push to the repository

By default Jenkins ignores Mavin build fails... change that by changing Jenkins global options

  • in Maven installations, the Global MAVEN_OPTS should have -Dmaven.test.failure.ignore=false
  • Manage Jenkins -> Configure System - in Maven installation

Change Jenkins' home directory

The current directory Jenkins home directory is visible by clicking Manage Jenkins -> Configure System

Why change Jenkins' default directory?

  • Can be useful to install on a drive where there is a lot of disk space for all the jobs and plugins.
  • Some projects may require a specific Jenkins directory

There is no need to do this unless you have one of the above situations.

How to change the home directory:

  1. make a new directory somewhere
  2. copy all files from old .jenkins to new directory
  3. change JENKINS_HOME environmental variable to new directory
    • on Windows, go to System properties to do this
    • on Mac, go to Terminal, type 'export JENKINS_HOME=<your new directory>', and then edit .bash_profile file in user home directory and add that same export statement there to make it permanent for all sessions
  4. restart Jenkins - Control-C to quit and restart or go to http://localhost:8080/restart in browser
  5. in web browser go to Manage Jenkins -> Configure System -> Home Directory to verify it is correct
  6. check out all system properties in browser: http://localhost:8080/systeminfo

References

  • How to use Jenkins - https://wiki.jenkins.io/display/JENKINS/Use+Jenkins
  • Raghav Pal - Jenkins YouTube series - https://www.youtube.com/watch?v=89yWXXIOisk&list=PLhW3qG5bs-L_ZCOA4zNPSoGbnVQ-rp_dG
  • Lynda.com - Continuous Integration video with Jenkins - https://www.lynda.com/Selenium-tutorials/Continuous-integration/521207/533051-4.html
  • Jenkins - Using Jenkins with Node.js - https://jenkins.io/doc/tutorials/building-a-node-js-and-react-app-with-npm/

What links here

  • Continuous integration ‎ (← links)
  • Agile Software Engineering Course Schedule ‎ (← links)
  • Bash shell and scripting ‎ (← links)
  • Unit testing assignment ‎ (← links)

dentoyarmsen.blogspot.com

Source: https://knowledge.kitchen/Using_Jenkins_for_continuous_integration

Post a Comment for "Integrate Protractor With Jenkins for Continuous"