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 Nowbutton on the job page. - Via REST API: Use a POST request to
http://JENKINS_URL/job/JOB_NAME/buildwith 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:1234567890abcdefExample
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:1234567890abcdefOutput
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
| Action | Method | URL | Notes |
|---|---|---|---|
| Trigger build via UI | Click | /job/JOB_NAME/ | Use 'Build Now' button |
| Trigger build via API | POST | /job/JOB_NAME/build | Requires authentication |
| Get API token | UI | /user/USER/configure | Needed for API calls |
| Check job status | GET | /job/JOB_NAME/lastBuild/api/json | Check 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.