devuan-releasebot

devuan's releasebot reimplemented (scorsh version)
git clone git://parazyd.org/devuan-releasebot.git
Log | Files | Refs | LICENSE

build.py (1608B)


      1 #!/usr/bin/env python3
      2 # See LICENSE file for copyright and license details.
      3 
      4 """
      5 Module to build Jenkins build jobs
      6 """
      7 
      8 import sys
      9 from os import environ as env
     10 from os.path import basename
     11 import jenkins
     12 
     13 from config import (dryrun, jobtypes, default_suites, supported_suites,
     14                     jenkins_host, jenkins_user, jenkins_pass)
     15 
     16 
     17 def main():
     18     """
     19     Main function
     20     """
     21     print('* Requested job build')
     22 
     23     print('- Connecting to Jenkins...')
     24     jenk = jenkins.Jenkins(jenkins_host, jenkins_user, jenkins_pass)
     25 
     26     try:
     27         jenk.get_whoami()
     28     except jenkins.JenkinsException:
     29         print('Error in request. Possible authentication fail.')
     30         sys.exit(1)
     31 
     32     # the -4 cuts off '.git' from the path
     33     pkgname = basename(env['SCORSH_REPO'])[:-4]
     34 
     35     for jobt in jobtypes:
     36         jobname = '-'.join([pkgname, jobt])
     37         if not jenk.job_exists(jobname):
     38             print('%s does not exist in Jenkins! Quitting.' % jobname)
     39             sys.exit(1)
     40 
     41     build_for = list(set(sys.argv[1:]).intersection(supported_suites))
     42     if not build_for:
     43         print('Error: no valid suites found in arguments. Exiting.')
     44         sys.exit(1)
     45         # in original releasebot it defaults to the declared suites if
     46         # no valid ones were passed
     47         # build_for = suites
     48 
     49     for build in build_for:
     50         print('- Building for %s' % build)
     51         if not dryrun:
     52             jenk.build_job(jobname, {'codename': build})
     53 
     54 
     55 if __name__ == '__main__':
     56     if len(sys.argv) > 1:
     57         main()
     58     else:
     59         print('Error: not enough arguments')
     60         sys.exit(1)