tag:blogger.com,1999:blog-7616276080941606824.post1969107958036783035..comments2024-03-20T02:18:57.507-07:00Comments on Practical JIRA Development: Adding components to JIRA automatically with a scriptMatt Doarhttp://www.blogger.com/profile/02360651363519410698noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-7616276080941606824.post-30830321394374071462013-05-08T11:55:12.826-07:002013-05-08T11:55:12.826-07:00'''
Add multiple components to multipl...<br />'''<br />Add multiple components to multiple projects<br /><br />Setup an environment with virtualenv <br />pip install jira-python<br /><br />Usage:<br /><br />(environment)[mdoar@mdoar2]$ time python ./add_components.py -z https://jira.example.com -x youruserid -y secret -d0<br /><br />Matt Doar<br />CustomWare<br />'''<br /><br />from jira.client import JIRA<br />from optparse import OptionParser<br />import logging<br />import os<br />import sys<br /><br />def connect_jira(log, options):<br /> '''<br /> Connect to JIRA. Return None on error<br /> '''<br /> try:<br /> log.info("Connecting to JIRA: %s" % options.jira_server)<br /> jira_options = {'server': options.jira_server}<br /> jira = JIRA(options=jira_options,<br /> # Note the tuple<br /> basic_auth=(options.jira_user, <br /> options.jira_password))<br /> return jira<br /> except Exception,e:<br /> log.error("Failed to connect to JIRA: %s" % e)<br /> return None<br /><br />def add_components(log, options, jira):<br /> '''<br /> Return non-zero on error<br /> '''<br /> component_names = [<br /> "Component A",<br /> "Component B",<br /> "Component C",<br /> ]<br /> <br /> project_keys = [<br /> "PROJA",<br /> "PROJB",<br /> ]<br /> <br /> for project_key in project_keys:<br /> for component_name in component_names:<br /> log.info("%s: creating component: %s" % (project_key, component_name))<br /> if not options.dryrun:<br /> res = jira.create_component(component_name,<br /> project_key)<br /><br /> return 0<br /> <br />def setup_logging(options, logname):<br /> '''<br /> '''<br /> logger = logging.getLogger(logname)<br /> logfilename = os.path.join(os.path.dirname(__file__), '%s.log' % logname)<br /> hdlr = logging.FileHandler(logfilename, 'w')<br /> formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')<br /> hdlr.setFormatter(formatter)<br /> logger.addHandler(hdlr) <br /> logger.setLevel(logging.WARNING)<br /> if options.verbose == 1:<br /> logger.setLevel(logging.INFO)<br /> elif options.verbose == 2:<br /> logger.setLevel(logging.DEBUG)<br /> <br /> ch = logging.StreamHandler(sys.stdout)<br /> ch.setLevel(logging.DEBUG)<br /> logger.addHandler(ch)<br /> logger = logger<br /> return logger<br /><br />def get_options():<br /> '''<br /> '''<br /> parser = OptionParser("usage: %prog [options]", version="%prog 0.1")<br /> <br /> parser.add_option("-d", "--dryrun", dest="dryrun", type="int",<br /> default=1,<br /> help="Set to zero for a non dryrun, i.e. actually import issues, default: %default") <br /> parser.add_option("-v", "--verbose", dest="verbose", type="int",<br /> default=1,<br /> help="Set to non-zero for more verbose output, default: %default")<br /> parser.add_option("-x", "--jirauser", dest="jira_user", default="admin",<br /> help="The JIRA user, default: %default")<br /> parser.add_option("-y", "--jirapassword", dest="jira_password", default="secret",<br /> help="The password for the JIRA user")<br /> parser.add_option("-z", "--jiraserver", dest="jira_server", default="http://localhost:8080",<br /> help="The JIRA server, default: %default.")<br /> <br /> (options, args) = parser.parse_args()<br /> return (options, args)<br /><br />def main():<br /> '''<br /> '''<br /> (options, args) = get_options()<br /> log = setup_logging(options, 'add_components')<br /><br /> jira = connect_jira(log, options)<br /> if not jira:<br /> return 1<br /><br /> res = add_components(log, options, jira)<br /> if res:<br /> return 1<br /><br /> return 0<br /><br />if __name__=="__main__":<br /> sys.exit(main())<br />Matt Doarhttps://www.blogger.com/profile/02360651363519410698noreply@blogger.comtag:blogger.com,1999:blog-7616276080941606824.post-54605623991072385152013-04-30T14:02:52.913-07:002013-04-30T14:02:52.913-07:00Someone please tell me how to do this with the Scr...Someone please tell me how to do this with the Script Runner plugin.Matt Doarhttps://www.blogger.com/profile/02360651363519410698noreply@blogger.comtag:blogger.com,1999:blog-7616276080941606824.post-21726492432922186772012-01-24T09:42:16.296-08:002012-01-24T09:42:16.296-08:00If you need to get past websudo for an action:
WE...If you need to get past websudo for an action:<br /><br />WEBSUDO_PAGE_URL=$SERVER_URL/secure/admin/WebSudoAuthenticate.jspa?webSudoPassword=$PASSWORD<br />curl --cookie $COOKIE_FILE_LOCATION --output /dev/null $WEBSUDO_PAGE_URLMatt Doarhttps://www.blogger.com/profile/02360651363519410698noreply@blogger.comtag:blogger.com,1999:blog-7616276080941606824.post-6186988424526541832012-01-12T11:44:29.806-08:002012-01-12T11:44:29.806-08:00Doing a similar thing with Perl: https://studio.pl...Doing a similar thing with Perl: https://studio.plugins.atlassian.com/wiki/display/JCLI/JIRA+Command+Line+Interface?focusedCommentId=33587342#comment-33587342Matt Doarhttps://www.blogger.com/profile/02360651363519410698noreply@blogger.comtag:blogger.com,1999:blog-7616276080941606824.post-71949445291080966822012-01-10T16:27:30.678-08:002012-01-10T16:27:30.678-08:00The JIRA CLI script at https://plugins.atlassian.c...The JIRA CLI script at https://plugins.atlassian.com/plugin/details/10751 has an example of doing this with Python. See JCLIMD-13 for more details.Matt Doarhttps://www.blogger.com/profile/02360651363519410698noreply@blogger.com