aboutsummaryrefslogtreecommitdiff
path: root/deliver.groovy
blob: b8057de4dc5aea8c25462b3de9cd26d2608bda83 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Parameters made available from Jenkins job configuration:
//   CONDA_INSTALLER_VERSION
//   CONDA_VERSION
//   aux_packages

this.py_maj_version = "3"
// The conda installer script to use for various <OS><py_version> combinations.
this.conda_installers  = ["Linux-py2":"Miniconda2-${CONDA_INSTALLER_VERSION}-Linux-x86_64.sh",
                          "Linux-py3":"Miniconda3-${CONDA_INSTALLER_VERSION}-Linux-x86_64.sh",
                          "MacOSX-py2":"Miniconda2-${CONDA_INSTALLER_VERSION}-MacOSX-x86_64.sh",
                          "MacOSX-py3":"Miniconda3-${CONDA_INSTALLER_VERSION}-MacOSX-x86_64.sh"]

this.CONDA_BASE_URL = "https://repo.continuum.io/miniconda"
// TODO: Consolidate in shared lib for convenience.
//if (this.CONDA_BASE_URL[-1..-1] == "/") {
//    this.CONDA_BASE_URL = [0..-2]
//}


def gen_specfiles(label) {
    
    node(label) {
    
        env.PYTHONPATH = ""
        // Make the log a bit more deterministic
        env.PYTHONUNBUFFERED = "true"
        def WORKDIR=pwd()
    
        // Delete any existing job workspace directory contents.
        // The directory deleted is the one named after the jenkins pipeline job.
        deleteDir()

        def OSname = null
        def uname = sh(script: "uname", returnStdout: true).trim()
        if (uname == "Darwin") {
            OSname = "MacOSX"
            println("OSname=${OSname}")
        }
        if (uname == "Linux") {
            OSname = uname
            println("OSname=${OSname}")
        }
        assert uname != null
        
        // Provide an isolated home directory unique to this build.
        sh "mkdir home"
        def HOME = "${WORKDIR}/home"
        
        // Check for the availability of a download tool and then use it
        // to get the conda installer.
        def dl_cmds = ["curl -OSs",
                       "wget --no-verbose --server-response --no-check-certificate"]
        def dl_cmd = null
        def stat1 = 999
        for (cmd in dl_cmds) {
            stat1 = sh(script: "which ${cmd.tokenize()[0]}", returnStatus: true)
            if( stat1 == 0 ) {
                dl_cmd = cmd
                break
            }
        }
        if (stat1 != 0) {
            println("Could not find a download tool. Unable to proceed.")
            sh "false"
        }
        
        def conda_install_dir = "${WORKDIR}/miniconda"
        def conda_installer =
            this.conda_installers["${OSname}-py${this.py_maj_version}"]
        dl_cmd = dl_cmd + " ${CONDA_BASE_URL}/${conda_installer}"
        sh dl_cmd    
        
        // Install specific version of miniconda
        sh "bash ./${conda_installer} -b -p ${conda_install_dir}"
        PATH = "${conda_install_dir}/bin:${PATH}"
        def cpkgs = "conda=${CONDA_VERSION}"
        
        def pkg_list = aux_packages.replaceAll('\n', ' ')
        withEnv(["PATH=${PATH}"]) {
            sh "conda install --quiet --yes ${cpkgs}"

            // Generate spec files
            sh "./mktestenv.sh -n 2018.1 -p 3.5 -i 1 ${pkg_list}"
            sh "./mktestenv.sh -n 2018.1 -p 3.6 -i 1 ${pkg_list}"
       
            // Make spec files available to master node. 
            stash name: "spec-stash-${OSname}", includes: "hstdp*.txt"
        }
    }
}

// Run the above function for each platform in parallel.
stage('create specfiles') {
    parallel( 
        Linux: { gen_specfiles('RHEL-6') },
        MacOS: { gen_specfiles('OSX-10.11') }
    )
}

node('boyle.stsci.edu') {
  stage('archive') {
    // Retrieve the spec files from the nodes where they were created.
    unstash "spec-stash-Linux"
    unstash "spec-stash-MacOSX"
    archive "hstdp*txt"
  }
}