class Jenkins < Formula desc "Extendable open source continuous integration server" homepage "https://jenkins.io/" url "https://get.jenkins.io/war/2.281/jenkins.war" sha256 "2e5ed61344faa04000d703d9b2077b9ec4dca4eb3f72b1eb5057b52e2b8e7458" license "MIT" livecheck do url "https://get.jenkins.io/war/" regex(%r{href=.*?v?(\d+(?:\.\d+)+)/?["' >]}i) end head do url "https://github.com/jenkinsci/jenkins.git" depends_on "maven" => :build end bottle :unneeded depends_on "openjdk@11" def install if build.head? system "mvn", "clean", "install", "-pl", "war", "-am", "-DskipTests" else system "#{Formula["openjdk@11"].opt_bin}/jar", "xvf", "jenkins.war" end libexec.install Dir["**/jenkins.war", "**/cli-#{version}.jar"] bin.write_jar_script libexec/"jenkins.war", "jenkins", java_version: "11" bin.write_jar_script libexec/"cli-#{version}.jar", "jenkins-cli", java_version: "11" end def caveats <<~EOS Note: When using launchctl the port will be 8080. EOS end plist_options manual: "jenkins" def plist <<~EOS Label #{plist_name} ProgramArguments #{Formula["openjdk@11"].opt_bin}/java -Dmail.smtp.starttls.enable=true -jar #{opt_libexec}/jenkins.war --httpListenAddress=127.0.0.1 --httpPort=8080 RunAtLoad EOS end test do ENV["JENKINS_HOME"] = testpath ENV.prepend "_JAVA_OPTIONS", "-Djava.io.tmpdir=#{testpath}" port = free_port fork do exec "#{bin}/jenkins --httpPort=#{port}" end sleep 60 output = shell_output("curl localhost:#{port}/") assert_match(/Welcome to Jenkins!|Unlock Jenkins|Authentication required/, output) end end