就像'build'命令用于从Jenkins CLI启动作业一样,有没有办法使用CLI或任何其他命令行技术取消长时间运行的作业。这是我在Windows机器上尝试,我不是要从任务管理器直接杀死进程或关闭jenkins。 请建议。
答案 0 :(得分:3)
您可以通过调用JOB_URL / lastBuild / stop
来停止Jenkins的执行答案 1 :(得分:0)
Jenkins内置命令行工具不提供取消/停止/中止正在运行的构建的方法。但幸运的是,jenkins提供了其他脚本API,如 Python API 和 Ruby 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
课程: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
答案 2 :(得分:0)
此选项假定您有权访问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>