api4jenkins
api4jenkins copied to clipboard
get all the configuration properties from a job ?
[ok, not really an issue, could be more of a question ; not sure there is a forum for questions - I tried StackOverflow, where I saw a tag for api4jenkins
]
I am trying to build stats on Jenkins jobs. I need to access a few of the job properties, like the URL of the git repo used, as seen in the UI ( here, in Source Code Management \ Git \ Repositories \ Repository URL )
However, I do not understand how to get that property , I am actually getting a small subset of the properties I see in the UI. ( my jobs are all FreeStyleProject )
from api4jenkins import Jenkins
client = Jenkins(JENKINS_BASE_URL, auth=(USERNAME, PASSWORD))
api_jobs = client.get_job('a_folder')
for j in api_jobs :
print(j.name) # FreeStyleProject, by the way
pprint.pprint(j.api_json())
pprint.pprint(j.configure())
-> no SCM, Git or Bitbucket properties in the returned data
@pbarthelemy there is no API to access the properties of job directly, but you can parse from configuration returned by job.configure()
; eg. git URL is in tag scm
<scm class="hudson.plugins.git.GitSCM" plugin="[email protected]">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url>test-git-url</url>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>*/master</name>
</hudson.plugins.git.BranchSpec>
</branches>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<submoduleCfg class="empty-list"/>
<extensions/>
</scm>
with python code:
import xml.etree.ElementTree as ET
print(ET.XML(job.configure()).find('<some xpath>'))