2014-03-06 22:06:53 +04:00
|
|
|
# verifies:
|
|
|
|
# 1. jenkins service starts on master node
|
|
|
|
# 2. jenkins user can be extended on both master and slave
|
|
|
|
# 3. jenkins service not started on slave node
|
2021-05-29 19:17:36 +03:00
|
|
|
# 4. declarative jobs can be added and removed
|
2014-04-11 19:15:56 +04:00
|
|
|
|
2019-11-24 22:54:10 +03:00
|
|
|
import ./make-test-python.nix ({ pkgs, ...} : {
|
2014-06-28 18:04:49 +04:00
|
|
|
name = "jenkins";
|
2021-01-10 22:08:30 +03:00
|
|
|
meta = with pkgs.lib.maintainers; {
|
2019-02-22 18:14:13 +03:00
|
|
|
maintainers = [ bjornfor coconnor domenkozar eelco ];
|
2015-07-12 13:09:40 +03:00
|
|
|
};
|
2014-04-14 16:02:44 +04:00
|
|
|
|
2014-02-11 00:07:12 +04:00
|
|
|
nodes = {
|
2014-04-11 19:15:56 +04:00
|
|
|
|
|
|
|
master =
|
2018-07-20 23:56:59 +03:00
|
|
|
{ ... }:
|
2021-05-29 19:17:36 +03:00
|
|
|
{ services.jenkins = {
|
|
|
|
enable = true;
|
|
|
|
jobBuilder = {
|
|
|
|
enable = true;
|
2022-07-12 23:25:36 +03:00
|
|
|
accessUser = "admin";
|
|
|
|
accessTokenFile = "/var/lib/jenkins/secrets/initialAdminPassword";
|
2021-05-29 19:17:36 +03:00
|
|
|
nixJobs = [
|
|
|
|
{ job = {
|
|
|
|
name = "job-1";
|
|
|
|
builders = [
|
|
|
|
{ shell = ''
|
|
|
|
echo "Running job-1"
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
{ job = {
|
|
|
|
name = "folder-1";
|
|
|
|
project-type = "folder";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
{ job = {
|
|
|
|
name = "folder-1/job-2";
|
|
|
|
builders = [
|
|
|
|
{ shell = ''
|
|
|
|
echo "Running job-2"
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
specialisation.noJenkinsJobs.configuration = {
|
|
|
|
services.jenkins.jobBuilder.nixJobs = pkgs.lib.mkForce [];
|
|
|
|
};
|
2014-03-06 22:06:53 +04:00
|
|
|
|
|
|
|
# should have no effect
|
|
|
|
services.jenkinsSlave.enable = true;
|
|
|
|
|
2018-06-30 02:55:42 +03:00
|
|
|
users.users.jenkins.extraGroups = [ "users" ];
|
2014-09-05 17:50:55 +04:00
|
|
|
|
2015-02-10 18:49:47 +03:00
|
|
|
systemd.services.jenkins.serviceConfig.TimeoutStartSec = "6min";
|
2014-03-06 22:06:53 +04:00
|
|
|
};
|
2014-04-11 19:15:56 +04:00
|
|
|
|
|
|
|
slave =
|
2018-07-20 23:56:59 +03:00
|
|
|
{ ... }:
|
2014-04-11 19:15:56 +04:00
|
|
|
{ services.jenkinsSlave.enable = true;
|
2014-03-06 22:06:53 +04:00
|
|
|
|
2018-06-30 02:55:42 +03:00
|
|
|
users.users.jenkins.extraGroups = [ "users" ];
|
2014-02-11 00:07:12 +04:00
|
|
|
};
|
2014-04-11 19:15:56 +04:00
|
|
|
|
2014-02-11 00:07:12 +04:00
|
|
|
};
|
|
|
|
|
2021-05-29 19:17:36 +03:00
|
|
|
testScript = { nodes, ... }:
|
|
|
|
let
|
|
|
|
configWithoutJobs = "${nodes.master.config.system.build.toplevel}/specialisation/noJenkinsJobs";
|
|
|
|
jenkinsPort = nodes.master.config.services.jenkins.port;
|
|
|
|
jenkinsUrl = "http://localhost:${toString jenkinsPort}";
|
|
|
|
in ''
|
2019-11-24 22:54:10 +03:00
|
|
|
start_all()
|
2014-02-11 00:07:12 +04:00
|
|
|
|
2022-07-18 11:17:40 +03:00
|
|
|
master.wait_for_unit("default.target")
|
2017-12-14 18:01:09 +03:00
|
|
|
|
2019-11-24 22:54:10 +03:00
|
|
|
assert "Authentication required" in master.succeed("curl http://localhost:8080")
|
2017-12-14 18:01:09 +03:00
|
|
|
|
2019-11-24 22:54:10 +03:00
|
|
|
for host in master, slave:
|
|
|
|
groups = host.succeed("sudo -u jenkins groups")
|
|
|
|
assert "jenkins" in groups
|
|
|
|
assert "users" in groups
|
2014-03-06 22:06:53 +04:00
|
|
|
|
2019-11-24 22:54:10 +03:00
|
|
|
slave.fail("systemctl is-enabled jenkins.service")
|
2021-05-29 19:17:36 +03:00
|
|
|
|
2022-04-01 21:03:29 +03:00
|
|
|
slave.succeed("java -fullversion")
|
|
|
|
|
2021-05-29 19:17:36 +03:00
|
|
|
with subtest("jobs are declarative"):
|
|
|
|
# Check that jobs are created on disk.
|
|
|
|
master.wait_until_succeeds("test -f /var/lib/jenkins/jobs/job-1/config.xml")
|
|
|
|
master.wait_until_succeeds("test -f /var/lib/jenkins/jobs/folder-1/config.xml")
|
|
|
|
master.wait_until_succeeds("test -f /var/lib/jenkins/jobs/folder-1/jobs/job-2/config.xml")
|
|
|
|
|
2022-07-12 23:25:36 +03:00
|
|
|
# Verify that jenkins also sees the jobs.
|
|
|
|
out = master.succeed("${pkgs.jenkins}/bin/jenkins-cli -s ${jenkinsUrl} -auth admin:$(cat /var/lib/jenkins/secrets/initialAdminPassword) list-jobs")
|
2021-05-29 19:17:36 +03:00
|
|
|
jobs = [x.strip() for x in out.splitlines()]
|
|
|
|
# Seeing jobs inside folders requires the Folders plugin
|
|
|
|
# (https://plugins.jenkins.io/cloudbees-folder/), which we don't have
|
|
|
|
# in this vanilla jenkins install, so limit ourself to non-folder jobs.
|
|
|
|
assert jobs == ['job-1'], f"jobs != ['job-1']: {jobs}"
|
|
|
|
|
|
|
|
master.succeed(
|
|
|
|
"${configWithoutJobs}/bin/switch-to-configuration test >&2"
|
|
|
|
)
|
|
|
|
|
|
|
|
# Check that jobs are removed from disk.
|
|
|
|
master.wait_until_fails("test -f /var/lib/jenkins/jobs/job-1/config.xml")
|
|
|
|
master.wait_until_fails("test -f /var/lib/jenkins/jobs/folder-1/config.xml")
|
|
|
|
master.wait_until_fails("test -f /var/lib/jenkins/jobs/folder-1/jobs/job-2/config.xml")
|
|
|
|
|
2022-07-12 23:25:36 +03:00
|
|
|
# Verify that jenkins also sees the jobs as removed.
|
|
|
|
out = master.succeed("${pkgs.jenkins}/bin/jenkins-cli -s ${jenkinsUrl} -auth admin:$(cat /var/lib/jenkins/secrets/initialAdminPassword) list-jobs")
|
2021-05-29 19:17:36 +03:00
|
|
|
jobs = [x.strip() for x in out.splitlines()]
|
|
|
|
assert jobs == [], f"jobs != []: {jobs}"
|
2014-02-11 00:07:12 +04:00
|
|
|
'';
|
2017-12-14 18:01:09 +03:00
|
|
|
})
|