Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reuse serverUrl for all job urls #9

Merged
merged 1 commit into from
Jun 19, 2014
Merged

reuse serverUrl for all job urls #9

merged 1 commit into from
Jun 19, 2014

Conversation

StefanScherer
Copy link
Contributor

Hello,

I have the problem to backup jenkins jobs from a Jenkins server that is running in a NAT network in a private cloud. I want to control it from outside from my host machine, as there is my cloned git repository.

My Gruntfile.js has a different IP address and port as Jenkins uses within the private cloud network for its Jenkins slaves.

module.exports = function(grunt) {
  grunt.initConfig({
    jenkins: {
      serverAddress: 'http://10.100.50.4:2200',
      username: 'YYYY',
      password: 'XXXX',
      pipelineDirectory: 'jenkins-configuration'
    }
  })
  grunt.loadNpmTasks('grunt-jenkins');
  grunt.registerTask('default', ['jenkins-list']);
};

If I list the jobs, you can see that the response from Jenkins returns a different IP address. That's the internal network for the jenkins swarm clients to connect to.

$ grunt jenkins-list
>> Using provided username and password

Running "jenkins-list-jobs" task
Found 8 jobs.
job: ubuntu1204-100gb_vcloud @ http://172.16.32.2/job/ubuntu1204-100gb_vcloud/
job: ubuntu1204-desktop_vcloud @ http://172.16.32.2/job/ubuntu1204-desktop_vcloud/
job: ubuntu1204_vcloud @ http://172.16.32.2/job/ubuntu1204_vcloud/
job: windows_2008_r2 @ http://172.16.32.2/job/windows_2008_r2/
job: windows_2008_r2_vcloud @ http://172.16.32.2/job/windows_2008_r2_vcloud/
job: windows_2012_r2_vcloud @ http://172.16.32.2/job/windows_2012_r2_vcloud/
job: windows_7_vcloud @ http://172.16.32.2/job/windows_7_vcloud/
job: windows_81_vcloud @ http://172.16.32.2/job/windows_81_vcloud/

Running "jenkins-list-plugins" task
plugin id: matrix-auth, version: 1.1
plugin id: matrix-project, version: 1.2
plugin id: pam-auth, version: 1.1

So the backup will hang as from my host machine I can't connect directly to that internal IP address. The result is this error after a long timeout:

$ grunt jenkins-backup
>> Using provided username and password

Running "jenkins-backup-jobs" task
Found 8 jobs.
Fatal error: Cannot read property 'statusCode' of undefined

I have changed the code that it reuses the given serverUrl from the Gruntfile.js and patches the responded urls for all jenkins jobs to have a correct url to connect to:

$ grunt jenkins-list
>> Using provided username and password

Running "jenkins-list-jobs" task
Found 8 jobs.
job: ubuntu1204-100gb_vcloud @ http://10.100.50.4:2200/job/ubuntu1204-100gb_vcloud/
job: ubuntu1204-desktop_vcloud @ http://10.100.50.4:2200/job/ubuntu1204-desktop_vcloud/
job: ubuntu1204_vcloud @ http://10.100.50.4:2200/job/ubuntu1204_vcloud/
job: windows_2008_r2 @ http://10.100.50.4:2200/job/windows_2008_r2/
job: windows_2008_r2_vcloud @ http://10.100.50.4:2200/job/windows_2008_r2_vcloud/
job: windows_2012_r2_vcloud @ http://10.100.50.4:2200/job/windows_2012_r2_vcloud/
job: windows_7_vcloud @ http://10.100.50.4:2200/job/windows_7_vcloud/
job: windows_81_vcloud @ http://10.100.50.4:2200/job/windows_81_vcloud/

Running "jenkins-list-plugins" task
plugin id: matrix-auth, version: 1.1
plugin id: matrix-project, version: 1.2
plugin id: pam-auth, version: 1.1

And then also the backup works from my host machine:

$ grunt jenkins-backup
>> Using provided username and password

Running "jenkins-backup-jobs" task
Found 8 jobs.
>> created file: jenkins-configuration/ubuntu1204-desktop_vcloud/config.xml
>> created file: jenkins-configuration/ubuntu1204_vcloud/config.xml
>> created file: jenkins-configuration/windows_2008_r2/config.xml
>> created file: jenkins-configuration/windows_2008_r2_vcloud/config.xml
>> created file: jenkins-configuration/windows_2012_r2_vcloud/config.xml
>> created file: jenkins-configuration/windows_7_vcloud/config.xml
>> created file: jenkins-configuration/ubuntu1204-100gb_vcloud/config.xml
>> created file: jenkins-configuration/windows_81_vcloud/config.xml

Running "jenkins-backup-plugins" task
>> created file: jenkins-configuration/plugins.json

Done, without errors.

The regex in the code replaces the protocol+host+port part and prepends the serverUrl. With that little change, which should work for all other 'normal' scenarios as well, I am even happier about this great automation tool!

sghill added a commit that referenced this pull request Jun 19, 2014
@sghill sghill merged commit 0a4730b into sghill:master Jun 19, 2014
@sghill
Copy link
Owner

sghill commented Jun 19, 2014

Wow, thanks for this pull request and the detailed walkthrough -- really great stuff!

Merging now and will push to npm in the next few days

@StefanScherer
Copy link
Contributor Author

Thanks for merging. I'll update my package.json after the new version is available.
In the meantime I have created a small network diagram in my README.md in the repo where I use grunt-jenkins. Works really smoothly now, and all controlled by the Vagrant host machine.

@sghill
Copy link
Owner

sghill commented Jun 24, 2014

Thanks again for the pull request! It is now live as version 0.5.0 on npm.

basebox-slave is a very interesting idea; I'm excited try it out. Thank you for sharing!

@StefanScherer
Copy link
Contributor Author

Thanks for the new release!
My basebox-slave was inspired by https://github.com/bsingr/jenkins-box, the nested hypervisors should also work in a VMware Fusion, but also other vagrant compatible "clouds" like vSphere, ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants