class JenkinsLts < Formula desc "Extendable open-source CI server" homepage "https://www.jenkins.io/index.html#stable" url "https://get.jenkins.io/war-stable/2.303.2/jenkins.war" sha256 "c4b8532e25a33001a3d8883d3cd87a664953ace239b486839b683065817d29cf" license "MIT" livecheck do url "https://www.jenkins.io/download/" regex(%r{href=.*?/war-stable/v?(\d+(?:\.\d+)+)/jenkins\.war}i) end bottle do sha256 cellar: :any_skip_relocation, all: "dc091c7b1c442ad9d3bda5d365462cc784ede8214bd0f6dda3e781dd3937ac1a" end depends_on "openjdk@11" def install system "#{Formula["openjdk@11"].opt_bin}/jar", "xvf", "jenkins.war" libexec.install "jenkins.war", "WEB-INF/lib/cli-#{version}.jar" bin.write_jar_script libexec/"jenkins.war", "jenkins-lts", java_version: "11" bin.write_jar_script libexec/"cli-#{version}.jar", "jenkins-lts-cli", java_version: "11" end def caveats <<~EOS Note: When using launchctl the port will be 8080. EOS end service do run [Formula["openjdk@11"].opt_bin/"java", "-Dmail.smtp.starttls.enable=true", "-jar", opt_libexec/"jenkins.war", "--httpListenAddress=127.0.0.1", "--httpPort=8080"] end test do ENV["JENKINS_HOME"] = testpath ENV.prepend "_JAVA_OPTIONS", "-Djava.io.tmpdir=#{testpath}" port = free_port fork do exec "#{bin}/jenkins-lts --httpPort=#{port}" end sleep 60 output = shell_output("curl localhost:#{port}/") assert_match(/Welcome to Jenkins!|Unlock Jenkins|Authentication required/, output) end end