@@ -94,6 +94,21 @@ def _check_job(self, job_name):
9494 raise CliException ('Job name does not esist' )
9595 return job_name
9696
97+ def _get_scm_name_and_node (self , xml_root ):
98+ scm_name = 'UnknownSCM'
99+ branch_node = None
100+ try :
101+ scm = xml_root .find ('scm' )
102+ if scm .attrib ['class' ] == 'hudson.plugins.mercurial.MercurialSCM' :
103+ scm_name = 'Mercurial'
104+ branch_node = scm .find ('revision' )
105+ elif scm .attrib ['class' ] == 'hudson.plugins.git.GitSCM' :
106+ scm_name = 'Git'
107+ branch_node = scm .find ('branches' ).find ('hudson.plugins.git.BranchSpec' ).find ('name' )
108+ except AttributeError :
109+ pass
110+ return (scm_name , branch_node )
111+
97112 def info (self , args ):
98113 job_name = self ._check_job (args .job_name )
99114 job_info = self .jenkins .get_job_info (job_name , 1 )
@@ -105,21 +120,21 @@ def info(self, args):
105120 "Last success build name: %s\n "
106121 "Build started: %s\n "
107122 "Building now: %s\n "
108- "Mercurial branch set: %s" )
123+ "%s branch set to : %s" )
109124 xml = self .jenkins .get_job_config (job_name )
110125 root = ElementTree .fromstring (xml .encode ('utf-8' ))
111- rev = 'Not Known'
112- scm = root .find ('scm' )
113- if scm is not None :
114- revision = scm .find ('revision' )
115- if revision is not None :
116- rev = revision .text
126+ scm_name , branch_node = self ._get_scm_name_and_node (root )
127+ if branch_node is not None :
128+ branch_name = branch_node .text
129+ else :
130+ branch_name = 'Unknown branch'
117131 print (info % (last_build .get ('fullDisplayName' , 'Not Built' ),
118132 last_build .get ('result' , 'Not Built' ),
119133 last_success_build .get ('fullDisplayName' , 'Not Built' ),
120134 datetime .datetime .fromtimestamp (last_build ['timestamp' ] / 1000 ) if last_build else 'Not built' ,
121135 'Yes' if last_build .get ('building' ) else 'No' ,
122- rev ))
136+ scm_name ,
137+ branch_name ))
123138
124139 def set_branch (self , args ):
125140 job_name = self ._check_job (args .job_name )
0 commit comments