How Do I Stop the Jenkins Pipeline?
Jenkins is a powerful automation server that helps developers build, test, and deploy their code continuously. Pipelines are the backbone of Jenkins, defining the steps involved in these automation processes. Sometimes, you might need to halt a running Jenkins pipeline, whether it's because of an error, a change in requirements, or simply to prevent further execution. This guide will walk you through the various ways to stop a Jenkins pipeline, catering to the average American reader who might be new to the intricacies of Jenkins.
Understanding Pipeline States
Before diving into stopping a pipeline, it's helpful to understand its different states. A pipeline can be in states like:
- Building: The pipeline is actively executing its stages.
- Queued: The pipeline is waiting for an available agent or resource to start.
- Aborted: The pipeline was intentionally stopped.
- Failed: The pipeline encountered an error and could not complete successfully.
- Success: The pipeline completed all its stages without errors.
Methods to Stop a Running Jenkins Pipeline
There are a few primary ways to stop a pipeline that is currently in the "Building" state.
Method 1: Stopping from the Jenkins UI (Build Console Output)
This is the most common and straightforward method for stopping a pipeline.
- Navigate to your Jenkins dashboard. This is your central hub for all Jenkins activities.
- Locate the specific pipeline you want to stop. Pipelines are typically listed under "Build History" or by clicking on the pipeline's name.
- Click on the running build number. Each time a pipeline runs, it gets a unique build number. Click on the number associated with the build you wish to stop. This will take you to the build's console output page.
- Find the "Abort Build" button. On the console output page, you'll see a prominent button, usually red, labeled "Abort Build" or "Stop Build." It might also have an icon resembling a stop sign.
- Click the "Abort Build" button. Jenkins will then send a signal to the agent executing the pipeline to stop.
You'll see the build status change to "Aborted" once the process is complete.
Method 2: Stopping from the Jenkins UI (Pipeline View)
If you're viewing the pipeline's visual representation (often a blue ocean or stage view), you can also stop it from there.
- Access the pipeline's visualization. This might be through the "Blue Ocean" plugin or the standard Jenkins stage view.
- Identify the running pipeline. Look for the visual indicator of an active build.
- Click on the running stage or build. This will usually bring up an option to stop or abort.
- Select the "Abort" or "Stop" option. Similar to the console output method, this will initiate the stopping process.
Method 3: Stopping a Pipeline via the Jenkins CLI
For more advanced users or for scripting purposes, the Jenkins Command Line Interface (CLI) can be used.
- Ensure you have the Jenkins CLI set up. This typically involves downloading the `jenkins-cli.jar` file and having Java installed.
-
Connect to your Jenkins server. You'll use a command like:
java -jar jenkins-cli.jar -s http://your-jenkins-url/ - Identify the job name and build number. You'll need to know the exact name of your pipeline job and the build number you want to stop.
-
Execute the stop command. The command to stop a build is:
build YOUR_JOB_NAME --abort
If you need to stop a specific build number, you might need to use a more detailed command or script to find the active build number. However, the `--abort` flag often targets the currently running build for that job.
Stopping Queued Pipelines
If a pipeline is in the "Queued" state, it means it hasn't started executing yet. You can cancel a queued pipeline in a couple of ways:
- From the Jenkins UI: Navigate to "Build Executor Status" or a similar queue management section. You should see your queued pipeline with an option to cancel it.
- By removing the build from the queue: Sometimes, simply going to the build's page and looking for a "Cancel" or "Remove from Queue" option will work.
What Happens When a Pipeline is Stopped?
When you stop a Jenkins pipeline, Jenkins attempts to gracefully terminate the running processes on the build agent. This means:
- Processes are terminated: Any commands or scripts being executed by the pipeline will be signaled to stop. This is usually done by sending a SIGTERM signal, which allows processes to shut down cleanly if they handle it. If they don't, a SIGKILL might be sent to force termination.
- Build status changes: The build status will officially be marked as "Aborted."
- Further stages are skipped: Any subsequent stages or steps in the pipeline will not be executed.
- Artifacts might not be saved: If the pipeline was stopped before it could save its artifacts (like build outputs or logs), those artifacts might be incomplete or not saved at all.
Important Considerations
While stopping a pipeline is usually a safe operation, keep a few things in mind:
- "Force Stop" might not be immediate: Sometimes, a pipeline might take a few moments to fully stop, especially if it's executing long-running processes that don't respond quickly to termination signals.
- Impact on downstream jobs: If your stopped pipeline is a trigger for other jobs, those downstream jobs will not run.
- Investigate the reason for stopping: If you find yourself frequently stopping pipelines, it's a good indicator that there might be underlying issues with your pipeline's logic or the build environment that need to be addressed.
FAQ Section
How do I know if my pipeline is actually stopped?
You'll see the status of the build change from "Building" to "Aborted" on the Jenkins dashboard and within the build's console output page.
Why would a pipeline get stuck and not stop immediately?
A pipeline might not stop immediately if the processes it's running are unresponsive to termination signals (like SIGTERM). This can happen with certain applications or scripts that don't properly handle shutdown requests, leading Jenkins to eventually force-kill them (SIGKILL).
Can I restart a pipeline after I've stopped it?
Once a build is "Aborted," you cannot restart that specific build number. You will need to trigger a new build of the pipeline, which will get a new build number.
What's the difference between "Aborted" and "Failed"?
"Aborted" means the pipeline was intentionally stopped by a user or an administrator. "Failed" means the pipeline encountered an error during its execution and could not complete successfully on its own.

