In simple terms, Jenkins API Tokens are like special passwords that allow software tools and scripts to access Jenkins.
Jenkins API tokens act as user passwords when talking to Jenkins API and allow performing operations from outside of Jenkins.
You might need API tokens when you want to trigger Jenkins actions like builds from a script or another software. One example of that is using it in webhooks.
You can also generate a token on behalf of another user if you’re a Jenkins admin.
Follow these steps to generate an API token for your own user.
Step 1: Login to Jenkins
Login to your Jenkins portal and from the top right click on your username. This will open your user profile.
Click on the “Configure” button from the left navigation tab:
Step 2: Create API Token
Under the “API Token” section, click on “Add new Token”. Give a descriptive name for this token and click “Generate”.
Step 3: Copy and store your API token securely
After you generate the API token, you can only copy it once. If you leave the page, you will not be able to retrieve an already-created token.
It’s important to save this token securely because anyone who knows it can perform Jenkins operations on your behalf. The token permissions are inherited from your user permissions.
Now you can use this token to perform Jenkins actions remotely e.g. from a script. See How to trigger the Jenkins job remotely.
This quick guide demonstrates how you can generate an API token for your user so you can use it when working with scripts or triggering Jenkins actions remotely.