-
-
Save yuri-hattori/e879f37e30cedee68e150bfec22726c9 to your computer and use it in GitHub Desktop.
clean_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'uri' | |
require 'fileutils' | |
require 'json' | |
uri = URI.parse("http://JENKINS_URL/api/json") | |
request = Net::HTTP::Get.new(uri) | |
request.basic_auth("user_name", "password") | |
req_options = { | |
use_ssl: uri.scheme == "https", | |
} | |
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| | |
http.request(request) | |
end | |
result = JSON.load(response.body) | |
jobs = result["jobs"].map{|job| job["name"] } | |
workspace_dirs = Dir.glob("../*") | |
workspace_dirs = workspace_dirs.map{|dir| File.basename(dir)} | |
workspace_dirs.each do |dir| | |
FileUtils.rm_rf("../#{dir}") unless jobs.include?(dir) | |
end | |
puts "Job of jenkins synchronization completed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment