Merge pull request #121841 from Pamplemousse/jenkins-cli
jenkins: Create the `jenkins-cli` command
This commit is contained in:
commit
f73efb9fb3
3 changed files with 69 additions and 8 deletions
|
@ -2,6 +2,7 @@
|
|||
with lib;
|
||||
let
|
||||
cfg = config.services.jenkins;
|
||||
jenkinsUrl = "http://${cfg.listenAddress}:${toString cfg.port}${cfg.prefix}";
|
||||
in {
|
||||
options = {
|
||||
services.jenkins = {
|
||||
|
@ -141,14 +142,34 @@ in {
|
|||
Additional command line arguments to pass to the Java run time (as opposed to Jenkins).
|
||||
'';
|
||||
};
|
||||
|
||||
withCLI = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to make the CLI available.
|
||||
|
||||
More info about the CLI available at
|
||||
<link xlink:href="https://www.jenkins.io/doc/book/managing/cli">
|
||||
https://www.jenkins.io/doc/book/managing/cli</link> .
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
# server references the dejavu fonts
|
||||
environment.systemPackages = [
|
||||
pkgs.dejavu_fonts
|
||||
];
|
||||
environment = {
|
||||
# server references the dejavu fonts
|
||||
systemPackages = [
|
||||
pkgs.dejavu_fonts
|
||||
] ++ optional cfg.withCLI cfg.package;
|
||||
|
||||
variables = {}
|
||||
// optionalAttrs cfg.withCLI {
|
||||
# Make it more convenient to use the `jenkins-cli`.
|
||||
JENKINS_URL = jenkinsUrl;
|
||||
};
|
||||
};
|
||||
|
||||
users.groups = optionalAttrs (cfg.group == "jenkins") {
|
||||
jenkins.gid = config.ids.gids.jenkins;
|
||||
|
@ -215,7 +236,7 @@ in {
|
|||
'';
|
||||
|
||||
postStart = ''
|
||||
until [[ $(${pkgs.curl.bin}/bin/curl -L -s --head -w '\n%{http_code}' http://${cfg.listenAddress}:${toString cfg.port}${cfg.prefix} | tail -n1) =~ ^(200|403)$ ]]; do
|
||||
until [[ $(${pkgs.curl.bin}/bin/curl -L -s --head -w '\n%{http_code}' ${jenkinsUrl} | tail -n1) =~ ^(200|403)$ ]]; do
|
||||
sleep 1
|
||||
done
|
||||
'';
|
||||
|
|
30
nixos/tests/jenkins-cli.nix
Normal file
30
nixos/tests/jenkins-cli.nix
Normal file
|
@ -0,0 +1,30 @@
|
|||
import ./make-test-python.nix ({ pkgs, ...} : rec {
|
||||
name = "jenkins-cli";
|
||||
meta = with pkgs.lib.maintainers; {
|
||||
maintainers = [ pamplemousse ];
|
||||
};
|
||||
|
||||
nodes = {
|
||||
machine =
|
||||
{ ... }:
|
||||
{
|
||||
services.jenkins = {
|
||||
enable = true;
|
||||
withCLI = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
start_all()
|
||||
|
||||
machine.wait_for_unit("jenkins")
|
||||
|
||||
assert "JENKINS_URL" in machine.succeed("env")
|
||||
assert "http://0.0.0.0:8080" in machine.succeed("echo $JENKINS_URL")
|
||||
|
||||
machine.succeed(
|
||||
"jenkins-cli -auth admin:$(cat /var/lib/jenkins/secrets/initialAdminPassword)"
|
||||
)
|
||||
'';
|
||||
})
|
|
@ -1,5 +1,5 @@
|
|||
{ lib, stdenv, fetchurl, common-updater-scripts, coreutils, git, gnused, nix
|
||||
, nixfmt, writeScript, nixosTests, jq, cacert, curl }:
|
||||
{ lib, stdenv, fetchurl, common-updater-scripts, coreutils, git, gnused, makeWrapper, nix
|
||||
, nixfmt, openjdk, writeScript, nixosTests, jq, cacert, curl }:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "jenkins";
|
||||
|
@ -10,9 +10,19 @@ stdenv.mkDerivation rec {
|
|||
sha256 = "0413ymfrb00ifxl8ww8nn8y4k07jhgsaxaw2h0qnfh9s6yxifpbf";
|
||||
};
|
||||
|
||||
nativeBuildInputs = [ makeWrapper ];
|
||||
|
||||
buildCommand = ''
|
||||
mkdir -p "$out/webapps"
|
||||
mkdir -p "$out/bin" "$out/share" "$out/webapps"
|
||||
|
||||
cp "$src" "$out/webapps/jenkins.war"
|
||||
|
||||
# Create the `jenkins-cli` command.
|
||||
${openjdk}/bin/jar -xf "$src" WEB-INF/lib/cli-${version}.jar \
|
||||
&& mv WEB-INF/lib/cli-${version}.jar "$out/share/jenkins-cli.jar"
|
||||
|
||||
makeWrapper "${openjdk}/bin/java" "$out/bin/jenkins-cli" \
|
||||
--add-flags "-jar $out/share/jenkins-cli.jar"
|
||||
'';
|
||||
|
||||
passthru = {
|
||||
|
|
Loading…
Reference in a new issue