How To Trigger Jenkins Builds Remotely And To Pass Parameters?
Last Updated :
11 Mar, 2024
Jenkins is an automation tool that is used to automate the build, test, and deploy stages of a software application. It allows the user to create a job and build the job by triggering remotely from any other external tool. Here in this guide, I will first discuss what is Jenkins. Then I will discuss why to trigger Jenkins to build a job remotely. After this, I will walk you through the different steps to trigger a Jenkins build remotely and pass parameters to it.
What Is Jenkins?
Jenkins is an open-source automation tool used to automate the build, test, and deploy stages of a software application. Jenkins helps developers to build and test and get build status more quickly. Basically, here, the moment new code is pushed to the version control system (like GitHub, GitLab, etc ) the pipeline automatically starts and Jenkins starts building and testing the code. If the new code is correctly integrating with the old code, then the , build status will be SUCCESS, or else the build status will be FAILURE. Due to this developers can write their code and fix the errors more quickly. Jenkins provides a very friendly user interface. It also provides many plugins which can be used in the automation of pipelines. Basically, Jenkins helps in automating the entire software development lifecycle. It automates the execution of various stages which helps in reducing any type of manual error and also helps in improving efficiency. With each new update, Jenkins is evolving and becoming more reliable for automating the software development process. Overall we can Jenkins has become a very important tool in the DevOps practice to accelerate the software development lifecycles.
Why To Trigger Jenkins Builds Remotely?
Trigger Jenkins build remotely means to start the building process of a job from any external tools scripts or browser. We can also pass custom parameters to the jobs while building them remotely. Triggering Jenkins build is important for the following reasons :
- Trigger Jenkins build remotely will allow the users to start the pipeline on some specific event occurrence such as new commits in the git repo or any new pull requests.
- This allows automation of the build process.
- It can help users to integrate with external tools to start the build process. For example python scripts or bash scripts.
- If someone wants to check whether their new code is working or not, they can just trigger the pipeline remotely.
- Parameters can be passed remotely to customize the job building on Jenkins.
Pre-requisites
Before moving next section make sure that you have installed Jenkins on your system. If Jenkins is not installed then follow these detailed geeks for geeks articles to install Jenkins on your system.
Steps To Trigger Jenkins Builds Remotely And Pass Parameters
Step 1 : Open Jenkins dashboard and create a new item.

Step 2 : Give the new item a name and select pipeline .

Step 3 : Add some build parameters by selecting `This project is parameterized` . Here i have added two string type build parameters , one parameter is to give username who is building the job and second parameter is to give a filename .

Step 4 : Then select `Trigger build remotely` . This option will enable you to build the job by using the URL only other browsers or scripts .

Step 5 : Now write declarative Jenkins pipeline . Here in this pipeline i am printing the username who is building it and creating a file .
pipeline {
agent any
stages {
stage('Author name') {
steps {
echo "This job is executed by ${params.whoami}"
}
}
stage('Creating File') {
steps {
echo "Filename: ${params.filename}"
echo "Creating..."
sh "echo 'Hello geeks' > ${params.filename}"
echo "File successfully created."
}
}
}
}

Step 6 : Now go to plugins . Install a plugin from available plugins called `Build Authorization Token Root`.

Step 7 : Now use the URL provided below and open it in another browser . The moment you opened the URL , this will automatically trigger to start the build process of the job .
http://localhost:8080/buildByToken/buildWithParameters?token=54321&job=GFG-Demo-Job&whoami=pranit&filename=test.txt (here you can give
your own parameters whoami and filename )

You can see the building of job successfully completed on the Jenkins dashboard .

Step 8 : Observe the outputs in console output .

In the workspace you will also observe that a filename `test.txt` is created .

Conclusion
Here in this guide you have learned about what is Jenkins . Then you have learned why is it required to trigger a Jenkins build remotely . Then you have created a job on Jenkins . In this job you have created two build parameters and also created a authentication token . After this you have written the Jenkins declarative pipeline code and then installed a plugin which allow you to access the Jenkins server from any other browser . Finally you have used the URL to remotely start a build process of a job from another browser and also observed the pipeline output in the console output .
Similar Reads
How To Reset Build Number In Jenkins?
Jenkins is an open-source automation server that is mainly used in building, testing, and deploying software projects. In some scenarios, you must have found yourself in a situation where you want to reset the build number in Jenkins. Whether it is because of organizational reasons, or you want to s
4 min read
How to pass Parameter to testng.xml from Command Line with Maven?
In test automation, we run tests across multiple web browsers. The TestNG with Maven allows us to pass the parameters through the command line dynamically; this enables us to control various test environments without editing the code again and again. Step to Pass Parameter to testng.xml from Command
3 min read
How to Build Python Application Using Jenkins ?
Jenkins is one of the most popular automation tools used worldwide for Continuous Integration and Continuous Delivery. It is a free and open-source automation server that enables developers to build, integrate and test the code automatically as soon as it is committed to the source repository. Build
7 min read
How to pass parameters in Postman requests?
Postman is an API(application programming interface) development tool that helps to build, test and modify APIs. It can make various types of HTTP requests(GET, POST, PUT, PATCH), save environments for later use, and convert the API to code for various languages(like JavaScript, and Python). In this
2 min read
How to Build React App in Jenkins?
Jenkins is a popular tool for Continuous Integration. Using Jenkins, we can externalize the build process for our code. It allows teams to collaborate more efficiently and deliver software in shorter cycles. In this article, we will learn how to build a react app in Jenkins. Steps To Install Jenkins
7 min read
How to pass java code a parameter from Maven for testing?
Maven is one of the most commonly used tools in Java projects for build automation, allowing the developer to manage the dependency of their project and many other operations, like compiling codes or running tests. Sometimes, you may want to pass some parameters from Maven to the Java code, so you c
3 min read
How to Pass Parameter from TestNG.xml File?
Parameters in TestNG allow you to configure test methods flexibly and make them more maintainable and reusable. The parameters feature allows you to pass data directly from the testng.xml file to test methods. This increases reusability at the suite level without the need to hard code values into th
3 min read
How To Setup Up Jenkins Webhooks For Automated Builds?
Jenkins is a broadly utilized open-source automation server that assists with automating the building, testing, and deployment of software applications. One of the main elements of Jenkins is its ability to coordinate with different tools and services. In this article, we will zero in on setting up
7 min read
How to Push a Local Branch to a Remote Repository in Git?
Git is a popular version control system that allows you to track changes in the codebase and collaborate with others. One of the common tasks in Git is pushing a local branch to a remote repository. This article will guide you through the steps to achieve this. Pushing Local BranchPushing a local br
2 min read
How to Pass the Query String Parameters to AWS Lambda Function or HTTP Endpoint?
In this article, we will explore the process of passing query string parameters from a client to the Backend Lambda or HTTP endpoint API gateway. As we know there are two types of integrations for Lambda and HTTP endpoints. The first kind is Proxy integration and second kind is Non-proxy integration
4 min read