【问题标题】:Cancelling Jenkins Job from Command line (CLI)从命令行 (CLI) 取消 Jenkins 作业
【发布时间】:2015-11-27 09:52:05
【问题描述】:

就像“构建”命令用于从 Jenkins CLI 启动作业一样,有没有办法使用 CLI 或任何其他命令行技术取消长时间运行的作业。这是我在 Windows 机器上尝试的,我不想直接从任务管理器中终止进程或关闭詹金斯。 请提出建议。

【问题讨论】:

  • 我认为批处理脚本中的错误退出应该停止工作。
  • 我没听懂。你能给我一个例子吗?顺便说一句,我正在将作业作为后台进程运行。
  • exit /b 用于退出脚本/命令。这应该停止运行脚本的詹金斯作业。
  • 这没有帮助。当我从 cmd 启动一次作业时,该作业在 jenkins 中启动,并且此命令不会影响继续运行的 jenkins 作业。我希望应该有 cli 命令来停止 jenkins 工作

标签: jenkins


【解决方案1】:

您可以通过调用 JOB_URL/lastBuild/stop 来停止 Jenkins 执行

【讨论】:

    【解决方案2】:

    Jenkins 内置命令行工具不提供取消/停止/中止正在运行的构建的方法。但幸运的是,jenkins 提供了其他脚本 API,如 Python APIRuby API 具有这种能力。

    Python API

    class jenkinsapi.build.Build(url, buildno, job, depth=1)

    stop()  
    Stops the build execution if it’s running :
    return boolean True if succeded    
    False otherwise or the build is not running
    

    API 链接:https://jenkinsapi.readthedocs.org/en/latest/build.html

    Ruby API

    类:JenkinsApi::Client::Job

    #stop_build(job_name, build_number = 0) ⇒ Object (also: #stop, #abort)
    Stops a running build of a job This method will stop the current/most recent build if no build number is specified.
    

    API 链接:http://www.rubydoc.info/gems/jenkins_api_client/1.4.2/JenkinsApi/Client/Job

    【讨论】:

      【解决方案3】:

      此选项假定您有权访问 Jenkins 安装。

      在 Jenkins >2.195 中,您可以使用 Jenkins CLI jar 执行此操作:

      # Export JENKINS_URL or add -s http://localhost[:port]/path/to/jenkins to the commands
      export JENKINS_URL=http://localhost:8080/jenkins
      
      # Get the name of the job you want to cancel
      java -jar /path/to/jenkins-cli.jar -auth user:secret list-jobs
      
      # Cancel the job
      java -jar /path/to/jenkins-cli.jar -auth user:secret stop_builds <job_name>
      
      # You can also disable the job, if needed
      java -jar /path/to/jenkins-cli.jar -auth user:secret disable_job <job_name>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-12-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-13
        相关资源
        最近更新 更多