1

I have a job in jenkins with a configuration, then, with the jenkins API in /cli i can get-job (API method) with an xml structure of my job and then i can create-job (API method) in jenkins with the followed xml.

?xml version='1.0' encoding='UTF-8'?>
<project>
 <actions/>
  <description></description>
  <keepDependencies>false</keepDependencies>
  <properties/>
<scm class="hudson.plugins.git.GitSCM" plugin="git@2.2.7">
<configVersion>2</configVersion>
<userRemoteConfigs>
  <hudson.plugins.git.UserRemoteConfig>
  <url>https://username:password@bitbucket.org/repoowner/project.git</url>
  <credentialsId>550e8400-e29b-41d4-a716-446655440000</credentialsId>
  </hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
....

Even if i give this url tag "https://username:password@bitbucket.org/repoowner/project.git" jenkins needs authentication to work, so in credentialsId tag jenkins give an UUID.

I want to be able to create a job dynamically by an external application with a given URL in this format "https://username:password@bitbucket.org/repoowner/project.git".

How can it be done?

Thanks.

Abraham Mesa
  • 83
  • 2
  • 11

2 Answers2

3

You can get the credentialsId via the API and the credentials-store plugin.

e.g. for credentials in global Domain

${ your-jenkins-domain }/credential-store/domain/_/api/xml

<domainWrapper>
 <credentials>
  <_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/>
 </credentials>
 <description></description>
 <displayName></displayName>
 <fullDisplayName></fullDisplayName>
 <fullName>credential-store/_</fullName>
 <global>true</global>
 <urlName>_</urlName>
</domainWrapper>

But on some point it is a bit tricky:
when accessing the xml api for global domain the id already has a '_' as prefix. When using other domains the prefix is missing (but in a job a prefix is added... couldn't figure out where the prefix can be found)

e.g. I stored github access data in a separated domain, the credentialsId tag was:

<XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/>

but used in a job id was:

0XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  • @Seemann : you mean the credentials plugin? I can't find credentials-store plugin. – user2434741 Apr 08 '17 at 19:14
  • To get the list, see http://stackoverflow.com/questions/43318727/how-to-get-the-list-of-credentialsid-of-jenkins-by-rest-api/43319933#43319933 – user2434741 Apr 10 '17 at 09:53
0

Actually i solve the problem just creating an generic user in bitbucket, then the UUID its always the same and i can just copy and paste that UUID to the others project.xml files.

Abraham Mesa
  • 83
  • 2
  • 11