Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.1k views
in Technique[技术] by (71.8m points)

post - How to disable a Jenkins job via curl?

I want to disable a Jenkins job by sending a post curl request to Jenkins.

I've tried doing that using:

  1. curl -X POST http://<server>:8080/<jobname>/disable
  2. curl -X POST http://<server>:8080/<jobname>/disable?token=<token>
  3. curl -u <username>:<token> POST http://<server>:8080/<jobname>/disable

but failed every time. The error i am getting is:

403 no valid crumb was included in the request

Is there a good curl based solution to this problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

No valid crumb means your Jenkins installation has a security option enabled which prevent requests send in a standard way to avoid one-click attacks. You can't use Jenkins CLI either, because it doesn't work yet.

Here are the steps using curl (replace localhost with your Jenkins address):

  1. Note your user API Token (from /user/USER/configure).
  2. Get your crumb:

    CRUMB=$(curl -s 'http://USER:TOKEN@localhost:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
    
  3. Now you can disable the job by sending the crumb in the headers:

    curl -X POST -H "$CRUMB" http://USER:TOKEN@localhost:8080/<jobname>/disable
    

    If the above won't work for some reason, you may try to use -u USER:TOKEN instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...