2

I am taking git repository,username and password as input from user and am creating a jenkins job using the below config.xml

<scm class="hudson.plugins.git.GitSCM" plugin="git@3.0.0">
    <configVersion>2</configVersion>
    <userRemoteConfigs>
      <hudson.plugins.git.UserRemoteConfig>
        **<url>"git repository path"</url>**
      </hudson.plugins.git.UserRemoteConfig>
    </userRemoteConfigs>    
  </scm>

I don't know the syntax for sending username and password in xml. Where should I add username and password in xml

susanoo
  • 85
  • 10
  • The simplest way is to define what you need in Jenkins UI and review the job config after – Ivan Nov 03 '16 at 10:39
  • actually my task is to take input from user from a jsp page and automatically set those value in jobs config file.I can't set these input manually in Jenkins UI – susanoo Nov 04 '16 at 08:38

2 Answers2

1

Jenkins uses encryption for the password it stores so you'll need to encrypt your password. Because you didn't specify your Jenkins Master version or which Git SCM plugin version you're using, the safest way to see the format of the configuration is to do as suggested in your question's comments and create a dummy job that uses Git, and see how to create that section inthe job.

Good luck!

Community
  • 1
  • 1
Dvir669
  • 6,577
  • 1
  • 20
  • 21
  • I using Jenkins ver. 2.11, Gitplugin 3.0.0.I had created a demo job in which I configured username and password manually.But when I am opening that job's config.xml , the data is stored in encrypted form in tag. What should I do? – susanoo Nov 07 '16 at 10:13
  • You need to handle the credentials before creating the job's xml. I don't know how you're generating it, using the API? CLI? – Dvir669 Nov 07 '16 at 16:57
0

I didn't know but there is an easy way to give username and password. I explicitly gave username and password separated by a colon before @ in the url.

https://username:password@bitbucket.org/username/my_jenkins.git

Please refer to below code:

<scm class="hudson.plugins.git.GitSCM" plugin="git@3.0.0">
<configVersion>2</configVersion>
<userRemoteConfigs>
  <hudson.plugins.git.UserRemoteConfig>
    <url>https://username:password@bitbucket.org/username/my_jenkins.git</url>
  </hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>    
mazend
  • 456
  • 1
  • 7
  • 37