blob: abcf1a8afc04347852e5bae04cfaa77d2bed06b7 [file] [log] [blame]
Jakub Josef65641f62018-01-26 17:34:26 +01001#!groovy
2
3// Collect parameters
4String mirror_name = env.MIRROR_NAME
5String mirror_target = env.MIRROR_TARGET ?: env.MIRROR_NAME
6
7String snapshot_name = env.SNAPSHOT_NAME as String
8String snapshot_id = env.SNAPSHOT_ID as String
9String snapshot_dir = env.SNAPSHOT_DIR
10String snapshot_rel_dir = env.SNAPSHOT_REL_DIR
11
12String root_dir = env.ROOT_DIR
13
14String slave_label = env.SLAVE_LABEL
15
16// Snapshot name can be hierarchical, i.e. can have subdirectories, so let's flatten it
17String normalized_snapshot_name = snapshot_name.replaceAll('/', '-')
18
19String _snapshot = ''
20
21node(slave_label) {
22 try {
23 dir(snapshot_dir) {
24 // Guess link target
25 if (snapshot_id ==~ /^\d{4}-\d{2}-\d{2}-\d{6}$/) {
26 // Exact snapshot ID
27 _snapshot = "${mirror_target}-${snapshot_id}"
28 } else if (snapshot_id == 'latest') {
29 // Latest available snapshot
30 _snapshot = sh (script: "sed '1p;d' '${mirror_target}-${snapshot_id}.target.txt'", returnStdout: true).trim()
31 } else {
32 // Some named snapshot
33 _snapshot = sh (script: "readlink '${mirror_target}-${snapshot_id}'", returnStdout: true).trim()
34 }
35
36 // Set name for the snapshot to prevent it from time-based cleanup
37 sh "ln -sfn '${_snapshot}' '${mirror_target}-${normalized_snapshot_name}'"
38 }
39
40 // Set top-level name
41 dir("${root_dir}/${snapshot_name}") {
42 sh "ln -sfn '${snapshot_rel_dir}/${_snapshot}' '${mirror_name}'"
43 sh "echo '${snapshot_rel_dir}/${_snapshot}' > '${mirror_name}'.target.txt"
44 }
45 } finally {
46 // Cleanup
47 dir("${snapshot_dir}@tmp") {
48 deleteDir()
49 }
50 dir("${root_dir}/${snapshot_name}@tmp") {
51 deleteDir()
52 }
53 }
54}
55
56// Set build description
57currentBuild.description = "<p><b>${_snapshot}</b> (from ${snapshot_id})</p>"
58