How to take Jenkins master node offline using CLI?

2019-07-23 16:15发布

I have been manually taking the master (and only) node offline whenever I sync our development database to avoid a bunch of false test failures. I have a script that does the full DB import and would like to automate the node maintenance as well.

How can I mark the master node temporarily offline using the command-line interface JAR?

  • I wrote a simple Bash script to execute Jenkins tasks.
  • I can authenticate using that script.

    $ jenkins who-am-i
    Authenticated as: david
    Authorities:
      david
      authenticated
    
  • However, I cannot get offline-node or online-node to recognize the master node. The help states that I can omit the node name for "master", but that doesn't work.

    $ jenkins offline-node
    Argument "NAME" is required
    java -jar jenkins-cli.jar online-node NAME
    Stop using a node for performing builds temporarily, until the next "online-node" command.
     NAME                : Slave name, or empty string for master
    

    It seems to be looking specifically for a slave, but I need to take the master's executor offline.

    $ jenkins offline-node master
    No such slave "master" exists. Did you mean "null"?
    

2条回答
Melony?
2楼-- · 2019-07-23 16:52

If you only have one build executor on the master and no standalone build nodes, use this command instead:

java -jar jenkins-cli.jar quiet-down

This will stop any new builds from executing. You can use

java -jar jenkins-cli.jar cancel-quiet-down

to put Jenkins back on line; at this point it will run any builds that were queued up while it was offline.

查看更多
手持菜刀,她持情操
3楼-- · 2019-07-23 17:09

It's not exactly intuitive, but the Jenkins documentation is correct. If you want to specify the master node for offline-node or online-node, use the empty string:

java -jar jenkins-cli.jar offline-node ""

That said, you should probably use @gareth_bowles answer anyways in case you add slaves in the future.

查看更多
登录 后发表回答