Start Jenkins build using batch script

后端 未结 6 1993
挽巷
挽巷 2020-12-15 23:43

I am working with a Jenkins build server to run synthesis/simulation for FPGAs. Right now I have nightly builds and can start the build manually in Jenkins browser interface

6条回答
  •  醉话见心
    2020-12-15 23:51

    In the new Jenkins Pipeline, under Build Triggers, select the checkbox Trigger builds remotely (e.g., from scripts). Then give Jenkins a token that will be required when triggering the build.

    Not authorized errors

    A problem with triggering the builds remotely is, if you've set up Jenkins right and disabled anonymous user access, you will get Not authorized errors when you try to trigger the build from a script (as @keocra pointed out). You now have two options:

    1. Pass a username and password along when you trigger the build. This means that your script will need to include the username and password, which means everyone who can read your script will have the username and password, which is almost as bad as anonymous access.
    2. Use the Build Token Root Plugin. This plugin allows you to use the Trigger builds remotely feature without requiring the username and password. All you need is the token you generated before.

    Triggering the build

    To trigger the build remotely, run

    curl JENKINS_URL/buildByToken/build?job=JobFoo&token=MyToken
    

    Where JENKINS_URL is the URL to your Jenkins instance, JobFoo is the name of your job, and MyToken is the token you entered under Trigger bulids remotely.

    Of course, you don't need to use curl; you can also use wget or any other program that can make HTTP requests.

提交回复
热议问题