0
0
JenkinsHow-ToBeginner · 3 min read

How to Trigger a Build Manually in Jenkins

To trigger a build manually in Jenkins, open the Jenkins web interface, navigate to your job, and click the Build Now button. Alternatively, you can trigger a build using the Jenkins REST API by sending a POST request to the job's build URL with proper authentication.
📐

Syntax

There are two common ways to trigger a Jenkins build manually:

  • Via Jenkins UI: Click the Build Now button on the job page.
  • Via REST API: Use a POST request to http://JENKINS_URL/job/JOB_NAME/build with authentication.

For the REST API, the syntax is:

curl -X POST http://JENKINS_URL/job/JOB_NAME/build --user USER:TOKEN

Here, USER is your Jenkins username and TOKEN is your API token or password.

bash
curl -X POST http://jenkins.example.com/job/my-job/build --user alice:1234567890abcdef
💻

Example

This example shows how to trigger a Jenkins job named my-job manually using the REST API with curl. Replace jenkins.example.com, alice, and the token with your details.

bash
curl -X POST http://jenkins.example.com/job/my-job/build --user alice:1234567890abcdef
Output
Started build #15 for job 'my-job'
⚠️

Common Pitfalls

Common mistakes when triggering builds manually include:

  • Not having proper permissions to trigger the build.
  • Using the wrong URL or job name in the REST API call.
  • Forgetting to include authentication in the API request.
  • Trying to trigger a build on a disabled job.

Example of a wrong API call without authentication:

bash
curl -X POST http://jenkins.example.com/job/my-job/build
# This will return a 403 Forbidden error because authentication is missing.

# Correct way with authentication:
curl -X POST http://jenkins.example.com/job/my-job/build --user alice:1234567890abcdef
📊

Quick Reference

ActionMethodURLNotes
Trigger build via UIClick/job/JOB_NAME/Use 'Build Now' button
Trigger build via APIPOST/job/JOB_NAME/buildRequires authentication
Get API tokenUI/user/USER/configureNeeded for API calls
Check job statusGET/job/JOB_NAME/lastBuild/api/jsonCheck build result

Key Takeaways

Use the Jenkins web UI 'Build Now' button for quick manual builds.
REST API POST requests can trigger builds programmatically with authentication.
Always include your Jenkins username and API token in API calls.
Ensure you have permission and the job is enabled before triggering builds.
Double-check job names and URLs to avoid errors.