Managing Jenkins Jobs
Jenkins is a powerful software development tool that offers an efficient platform for continuous integration and delivery (CI/CD) pipelines. This guide provides an in-depth exploration of Jenkins, featuring different job types and views, organizational strategies, and best practices for configuration. It is a valuable resource for anyone seeking to optimize their use of Jenkins in software development.
Table of contents
- Understanding Jenkins jobs
- How to access Jenkins jobs
- Freestyle projects
- Pipeline projects
- Multi-configuration projects
- Multibranch pipeline jobs
- Best practices for job configuration
- Conclusion
Understanding Jenkins jobs
What are Jenkins jobs?
Jenkins jobs serve as the backbone of automation within the software development lifecycle. These individual tasks or processes streamline critical stages, including building, testing, and deploying applications. By leveraging diverse job types, Jenkins allows for the customization of workflows, ensuring adaptability to specific project requirements.
These jobs encapsulate the importance of continuous integration and delivery by empowering the teams to automate and optimize their development processes for increased efficiency and reliability.
Types of Jenkins jobs
Freestyle Projects
Freestyle projects are the fundamental building blocks of Jenkins jobs, and they offer a flexible platform for setting up building steps with ease, thanks to an intuitive graphical interface. This approach is perfect for projects with simple automation requirements, providing a fast and easy way for those new to Jenkins to get started.
Pipeline Jobs
Jenkins’ flexibility is signified in its Pipeline jobs, which allow users to define jobs as code through Jenkins Pipeline. This provides users with unprecedented control over complex build and deployment processes. This approach is ideal for projects with intricate workflows, dependencies, and a need for high customization. It ensures transparency and maintainability in the CI/CD pipeline.
Multi-Configuration Projects
Matrix or multi-configuration projects bring versatility by enabling testing across various configurations. In each job run, the same job is executed with different parameters. This approach is valuable for projects that demand comprehensive compatibility testing across diverse environments, ensuring the software’s robustness across various scenarios.
Multibranch Pipeline Jobs
Multibranch pipeline jobs automatically identify branches in a repository and execute builds based on a defined pipeline, ensuring continuous integration for every code branch. Essential for projects managing multiple branches, this approach guarantees seamless integration for each code iteration and simplifies the management of varied development streams.
Folder Jobs
Folders in Jenkins provide a way to organize and categorize jobs. A Folder job allows you to group related jobs, making it easier to manage and navigate through large numbers of jobs. It serves as a container for organizing and structuring jobs based on projects, teams, or any other logical grouping. Folders help maintain a clean and structured Jenkins environment, especially in scenarios where there are numerous jobs with different purposes.
Organizational Folder
An Organizational Folder, also known as a View or Nested View, takes the concept of job organization a step further. It allows you to create a hierarchical folder structure, providing a more sophisticated way to organize and manage jobs in Jenkins.
This type of folder is beneficial for large organizations or projects with complex architectures, as it creates a nested hierarchy of folders, making it easier to navigate and maintain a clear structure in the Jenkins instance. Organizational Folders enhance scalability and maintainability, offering a high-level overview of the entire Jenkins pipeline.
How to access Jenkins jobs
Accessing Jenkins jobs is a fundamental step in leveraging its capabilities. It involves a series of steps:
Log in to Jenkins
Open your preferred web browser and enter the URL for your Jenkins instance http://localhost:8080
. You’ll be prompted to enter your credentials. Input your username and password and click Sign In.
Navigate to dashboard
After successful login, you will be directed to the Jenkins dashboard. The dashboard is the central hub for managing all your Jenkins jobs, views, and configurations.
Select a job type
To create a new job, locate and click on the New Item option, usually located on the left-hand side of the dashboard. You may need the appropriate permissions to create new items; if you don’t see the New Item option, check your user permissions with your Jenkins administrator.
Choose the desired job type
You’ll be prompted to give your new job a name on the New Item page. Enter a descriptive name for your job.
Select the type of job you want to create. This could be a Freestyle project, Pipeline, Multi-Configuration project, etc. Then, click the OK button at the bottom of the page.
Configure job settings
Once you’ve selected the job type, you’ll be taken to a configuration page where you can define various settings. This includes specifying build steps, adding parameters, configuring source code management, and other job-specific settings. Take the time to configure these settings to align with your project requirements carefully.
Note
We have described these settings and parameters for every job type below.
Save the job configuration
After configuring the job settings, scroll to the bottom of the page and click the Save or Apply button. This will save your job configuration and redirect you to the main dashboard.
Trigger the job
Depending on your project requirements, you can manually trigger the job or set up automated triggers. To manually trigger the job, locate your job on the dashboard and click the Build Now option.
Return to the job configuration page for automated triggers by clicking the Configure tab on the dashboard and finding the Build Triggers section. Configure triggers based on events such as code commits or scheduled builds.
Freestyle projects
Freestyle projects in Jenkins provide a versatile platform for configuring builds through an intuitive graphical interface. A Freestyle project typically consists of several sections or tabs, each serving a specific purpose.
Let’s explore these tabs and their respective elements:
General
Description Tab
This allows you to describe the project briefly. And having below checkboxes:
Discard Old Builds: Controls whether to discard old builds to free up space.
GitHub Project: Indicates that this project is associated with a GitHub repository.
This Project is Parameterized: Enables parameterization of the project.
Throttle Builds: Manages the rate of builds for this project.
Execute Concurrent Builds if Necessary: Allows the project to run concurrently if needed.
Source code management
None: If the project doesn’t involve source code management.
Git: Configures Git as the version control system, including repository URL and credentials.
Build triggers
Trigger Builds Remotely: Allows remote triggering of builds.
Build After Other Projects are Built: Specifies to build after other specified projects.
Build Periodically: Enables scheduling builds at specified intervals.
GitHub Hook Trigger for GITScm Polling: Triggers builds based on GitHub hook events.
Poll SCM: Periodically polls the source code management system for changes.
Build environment
Delete Workspace Before Build Starts: Clears the workspace before starting a new build.
User Secret Texts or Files: Manages secret texts or files during the build.
Add Timestamps to the Console Output: Appends timestamps to build console output.
Inspect Build Log for Published Build Scans: Checks the build log for published build scans.
Terminate a Build If It’s Stuck: Aborts the build if it’s stuck.
With Ant: Configures Ant as part of the build environment.
Build steps
Add Build Steps (Dropdown)
Execute Windows Batch Command: Executes Windows batch commands.
Execute Shell: Executes shell commands.
Invoke Ant: Invokes Ant build tasks.
Invoke Gradle Script: Executes Gradle build scripts.
Run with Timeout: Sets a time limit for build steps.
Post-build actions
Add Post-Build Action(Dropdown)
Aggregate Downstream Test Results: Collect test results from downstream projects.
Archive the Artifacts: Stores specified files as build artifacts.
Build Other Projects: Triggers other projects after the completion of this one.
Publish JUnit Test Result Report: Publishes JUnit test results.
Git Publisher: Publishes changes to Git repositories.
Save and apply
Save: Commits the configured changes to the project settings.
Apply: Applies the changes temporarily for previewing without committing.
Pipeline projects
Pipeline projects in Jenkins offer a powerful way to define and manage continuous delivery pipelines as code. These projects are organized into three main sections or tabs, each serving a specific purpose.
Let’s delve into these tabs and their corresponding elements:
General
Description Tab
This allows you to describe the pipeline briefly. And having below checkboxes
Discard Old Builds: Manages whether to discard old builds to free up space.
Do Not Allow Concurrent Builds: Prevents multiple pipeline builds from running simultaneously.
Do Not Allow the Pipeline to Resume if the Controller Restarts: Controls pipeline behavior after the controller restarts.
GitHub Project: Indicates association with a GitHub repository.
Pipeline Speed/Durability Override: Adjusts the pipeline’s speed or durability.
Preserve Stashes from Completed Builds: Retains stashes from completed builds.
This Project is Parameterized: Enables parameterization of the pipeline.
Throttle Builds: Manages the rate of builds for this pipeline.
Advanced project options
This tab contains additional advanced settings, though the specific options can vary based on Jenkins plugins and configurations.
Pipeline script
This tab is the core of the pipeline project, where you define the entire pipeline script as code. The pipeline script uses the Groovy-based DSL (Domain-Specific Language) specific to Jenkins Pipelines. It includes stages, steps, and directives to define the continuous delivery process.
Multi-configuration projects
Multi-Configuration Projects in Jenkins provide a flexible way to test various configurations. These projects are organized into eight sections or tabs, each serving a specific purpose.
Let’s explore these tabs and their corresponding elements:
General
Description Tab
This allows you to describe the project briefly. And having below checkboxes:
Discard Old Builds: Manages whether to discard old builds to free up space.
GitHub Project: Indicates association with a GitHub repository.
This Project is Parameterized: Enables parameterization of the project.
Throttle Builds: Manages the rate of builds for this project.
Execute Concurrent Builds If Necessary: Allows concurrent builds if needed.
Advanced project options
This tab contains additional advanced settings, though the specific options can vary based on Jenkins plugins and configurations.
Source code management
None: If the project doesn’t involve source code management.
Git: Configures Git as the version control system, including repository URL and credentials.
Build triggers
Though specifics can vary, this tab contains settings configuring triggers for starting builds.
Configuration matrix
Combination Filter: Defines a filter for selecting configurations to build.
Run Each Configuration Sequentially: Specifies to run each configuration one after the other.
Execute Touchstone Build First: Run the touchstone build before different configurations.
Build environment
This tab includes settings related to the environment in which the builds are executed, e.g., configuring build agents, setting environment variables, etc.
Build steps
This tab lets you define the steps to execute during the build process. Similar to the Build Steps tab in Freestyle projects, but with additional configuration options specific to multi-configuration builds.
Post-build actions
This tab allows you to define actions to be taken after the completion of the build. Similar to the Post-Build Actions tab in Freestyle projects, but with additional configuration options specific to multi-configuration builds.
Multibranch pipeline jobs
Multibranch Pipeline Jobs in Jenkins allow the automatic creation of branches as individual projects, each with its build configuration. These projects are organized into eight sections or tabs, each serving a specific purpose.
Let’s explore these tabs and their corresponding elements:
General
Description Tab: This allows you to describe the multibranch pipeline briefly.
Display Name Tab: Specifies a display name for the multibranch pipeline.
Branch sources
Add Source Dropdown Tab
Git: Configures Git as the source.
GitHub: Configures GitHub as the source.
Single Repository and Branch: Manually specifies a single repository and branch.
Build configuration
Mode Bar: Displays the build mode, likely with the option by Jenkinsfile.
Script Path Bar: Specifies the path to the Jenkinsfile script.
Scan multibranch pipeline triggers
Periodically If Not Otherwise Run: Triggers a scan periodically if not run otherwise.
Orphaned item strategy
Abort Builds: Aborts build for orphaned branches.
Discard Old Items: Discard old items for orphaned branches.
Appearance
This tab contains settings related to the appearance of the multi-branch pipeline.
Health metrics
This tab contains settings related to health metrics, monitoring the overall health of the multi-branch pipeline.
Properties
Docker Label: Specifies the Docker label for running builds.
Docker Registry URL: Configures the URL of the Docker registry.
Registry Credentials: Manages credentials for accessing the Docker registry.
Note
We have excluded the elements of Folder Jobs and Organizational Folder because they contain the same elements as the four job types described.
Best practices for job configuration
Implementing best practices for job configuration is crucial for maintaining an efficient and scalable CI/CD pipeline. This includes a set of guidelines and strategies:
Logical naming conventions
Selecting the correct name for your job is essential. This aids in understanding and managing your CI/CD landscape effectively. A well-chosen name simplifies navigation and ensures clarity for all team members.
When choosing a name, stick to guidelines such as using alphanumeric characters, underscores, and hyphens. Ensure your job name starts with a letter, avoids special characters, and defines its purpose. Jenkins job names are case-sensitive, so maintain consistency in letter casing. Avoid spaces in names to prevent issues with command-line interactions.
Parameterized jobs for enhanced adaptability
Parameterized jobs in Jenkins offer a dynamic approach to configuring your CI/CD pipeline, enabling adaptability to varying project requirements. Despite the absence of an exact Parameterized Job type in Jenkins, you can achieve similar functionality by incorporating parameters into job configurations. For instance, you can utilize parameters like strings, booleans, or choices in Freestyle and Pipeline jobs.
Additionally, some projects feature a checkbox labeled This project is parameterized, enabling parameterization for that specific project. By embracing this checkbox and incorporating parameters, you empower users to customize job executions based on dynamic inputs, ensuring your CI/CD pipeline remains versatile and responsive to various project scenarios.
Security measures for Jenkins jobs
Protecting Jenkins jobs is crucial for maintaining the integrity of your CI/CD pipeline. Implement robust security measures using Role-Based Access Control (RBAC) and plugin-specific security settings. RBAC serves as a cornerstone, allowing you to define roles and permissions.
To implement RBAC, access the Jenkins dashboard, navigate to Manage Jenkins, and select Security. Enable security, opt for Jenkins’ user database, and define roles with specific permissions. This helps in controlling access to critical job configurations.
Additionally, leverage plugin-specific settings to tailor security configurations based on your project’s unique needs. Install relevant plugins that enhance security measures, providing fine-grained control over user access and actions. Combining RBAC and plugin-specific settings, this two-pronged approach strengthens your Jenkins environment against unauthorized access and malicious activities, ensuring a secure and reliable CI/CD pipeline.
Automated Build Triggers for Streamlined CI/CD
Efficient CI/CD pipelines depend on automated build triggers, reducing manual intervention and ensuring consistent build initiations. Critical events like code commits and pull requests serve as key triggers. To set up automated build triggers in Jenkins, navigate to the job configuration of your respective job types and access the Build Triggers section.
Among the available options, Build periodically is a powerful tool for automated scheduling. This checkbox allows you to define a schedule using the CRON syntax, ensuring that builds occur at specified intervals, promoting regularity and predictability in your pipeline.
Additionally, Build after other projects are built offers a seamless way to cascade builds. Selecting this option will automatically trigger your job upon completing specified upstream projects. This inter-project coordination streamlines the development workflow, automating subsequent builds based on project dependencies.
These checkboxes, Build periodically and Build after other projects are built, contribute significantly to the efficiency and automation of your CI/CD pipeline in Jenkins.
Note
The bold italicized letters are the checkboxes belonging to the Build Trigger tab. We have described these elements well for every job type above.
Final thoughts on managing Jenkins jobs and views
In conclusion, effectively managing Jenkins’s jobs and views is a multi-faceted undertaking that requires a deep understanding of the diverse types of jobs, thoughtful organizational strategies, and adherence to best practices.
By integrating these insights into Jenkins workflows, development teams can confidently navigate the complexities of modern software development, fostering a culture of continuous integration and delivery. When managed meticulously, Jenkins becomes an automation tool and a strategic asset that propels software development toward efficiency, reliability, and scalability.
Related articles
- Jenkins installation guide
- Jenkins pipelines
- Declarative vs Scripted Jenkins pipelines
- Jenkins-JMeter integration
Follow our blog
Be the first to know when we publish new content.
Jenkins Jobs Detailed Guide
- Top 10 API Testing Tools - April 6, 2024
- The ABCs of UAT Testing: Understanding User Acceptance Testing - March 21, 2024
- Agile Testing: Key Principles and Practices - March 15, 2024