Bringing Jenkins Remote Access API To The Masses
Cliffano Subagio (@cliffano) - Shine Solutions
G’Day
Cliffano Subagio (@cliffano)
Shine Solutions, Australia
Jenkins (nee Hudson)
- User since 2007
- Contributor since 2008
Menu:
- Jenkins and I
- Remote Access API
- Introducing Swaggy Jenkins
- Demo Time
- What’s next?
Once upon a time…
My Mission:
To extend Jenkins.
1. Chuck Norris Plugin
2. JSGames Plugin
3. Speakable Items
4. Firefox Add-on Build Monitor
5. Nestor
Remote Access API: What Is It?
• REST-like style
• HTTP basic authentication
• CSRF protection token
• JSON/XML responses
Remote Access API: What Can It Do?
• Build, create, delete, enable, disable a job
• Create, delete a view
• Get job and view config.xml
• List jobs status, queued jobs, executors
• Get build console output
• Get Jenkins version
Build A Job + Stream Console Output
Build A Job + Stream Console Output
Client Library
api = new RemoteAccessApi(username, password);
crumb = api.getCrumb();
api.setCrumb(crumb);
job = api.buildJob(‘myjob’);
job.isInQueue();
job.getConsoleOutput();
Existing Client Libraries
• node.js: jenkins, jenkins-api,jenkins2-api, smithers
• python: pyjenkins, jenkins-webapi, jenkins-build
• ruby: jenkins, jenkins_api_client, jenkins-json-api
• perl: Jenkins::API, Net::Jenkins
• More…
Challenges I’m Trying To Solve
• Lack of parity between clients
• Maintainers availability
• Growing number of technology stacks
Introducing Swagger CodeGen
• Generates code from an OpenAPI specification
• Endpoints, parameters, models
• Support 70+ technology stacks

and counting…
Supported Technology Stacks
My New Mission:
To enable others to integrate Jenkins
with as many technologies as possible.
Introducing Swaggy Jenkins
• Code generated from OpenAPI spec for Jenkins
• Rapid change and regenerate!
• 70+ libraries
• Published to npmjs.com, PyPI, RubyGems.org

More to follow…
• Available on github.com/cliffano/swaggy-jenkins
Building An OpenAPI Specification
• Specify info, schemes, security
• Specify paths, parameters, responses
• Generate response model definitions
• Total: 2840 lines long

45% of which are response model definitions
Converting Response Models
Jenkins response JSON OpenAPI Definitions
Generating Response Model Definitions
• `swaggy-jenkins response2definition

remoteaccess-responses/

--reporter file

--out-file remoteaccess-definitions.yml`
• Result: 1274 lines of definitions
• Regenerate when there’s a response JSON update
70+ Generated Libraries
Demo 1: Nestor CLI + Remote Access API
Demo 2 - api.ai + Remote Access API
Demo 3: Slack Chatbot + Blue Ocean API
What Is Blue Ocean API?
• Used by Blue Ocean UX
• Private API
• JSON Web Token
• Pipeline, run, queue, log
• User, organisation, SCM
Run A Pipeline
What’s Next?
• Upgrade to OpenAPI 3.0
• JWT authentication support
• Folder support
• Future of Jenkins API?
Conclusions
Resources
• Swaggy Jenkins - https://github.com/cliffano/swaggy-
jenkins
• Nestor - https://github.com/cliffano/nestor
• Jenkins api.ai Demo - https://github.com/cliffano/jenkins-
apiai-demo
• Jenkins Slack Demo - https://github.com/cliffano/jenkins-
slack-demo
• Jenkins Remote Access API - https://wiki.jenkins.io/display/
jenkins/remote+access+api
• Jenkins Blue Ocean API - https://github.com/jenkinsci/
blueocean-plugin/tree/master/blueocean-rest
Questions?
Bringing Jenkins Remote Access API To The Masses

Bringing Jenkins Remote Access API To The Masses

  • 1.
    Bringing Jenkins RemoteAccess API To The Masses Cliffano Subagio (@cliffano) - Shine Solutions
  • 2.
    G’Day Cliffano Subagio (@cliffano) ShineSolutions, Australia Jenkins (nee Hudson) - User since 2007 - Contributor since 2008
  • 3.
    Menu: - Jenkins andI - Remote Access API - Introducing Swaggy Jenkins - Demo Time - What’s next?
  • 4.
    Once upon atime…
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
    4. Firefox Add-onBuild Monitor
  • 10.
  • 11.
    Remote Access API:What Is It? • REST-like style • HTTP basic authentication • CSRF protection token • JSON/XML responses
  • 12.
    Remote Access API:What Can It Do? • Build, create, delete, enable, disable a job • Create, delete a view • Get job and view config.xml • List jobs status, queued jobs, executors • Get build console output • Get Jenkins version
  • 13.
    Build A Job+ Stream Console Output
  • 14.
    Build A Job+ Stream Console Output
  • 15.
    Client Library api =new RemoteAccessApi(username, password); crumb = api.getCrumb(); api.setCrumb(crumb); job = api.buildJob(‘myjob’); job.isInQueue(); job.getConsoleOutput();
  • 16.
    Existing Client Libraries •node.js: jenkins, jenkins-api,jenkins2-api, smithers • python: pyjenkins, jenkins-webapi, jenkins-build • ruby: jenkins, jenkins_api_client, jenkins-json-api • perl: Jenkins::API, Net::Jenkins • More…
  • 17.
    Challenges I’m TryingTo Solve • Lack of parity between clients • Maintainers availability • Growing number of technology stacks
  • 18.
    Introducing Swagger CodeGen •Generates code from an OpenAPI specification • Endpoints, parameters, models • Support 70+ technology stacks
 and counting…
  • 19.
  • 20.
    My New Mission: Toenable others to integrate Jenkins with as many technologies as possible.
  • 21.
    Introducing Swaggy Jenkins •Code generated from OpenAPI spec for Jenkins • Rapid change and regenerate! • 70+ libraries • Published to npmjs.com, PyPI, RubyGems.org
 More to follow… • Available on github.com/cliffano/swaggy-jenkins
  • 22.
    Building An OpenAPISpecification • Specify info, schemes, security • Specify paths, parameters, responses • Generate response model definitions • Total: 2840 lines long
 45% of which are response model definitions
  • 23.
    Converting Response Models Jenkinsresponse JSON OpenAPI Definitions
  • 24.
    Generating Response ModelDefinitions • `swaggy-jenkins response2definition
 remoteaccess-responses/
 --reporter file
 --out-file remoteaccess-definitions.yml` • Result: 1274 lines of definitions • Regenerate when there’s a response JSON update
  • 25.
  • 26.
    Demo 1: NestorCLI + Remote Access API
  • 28.
    Demo 2 -api.ai + Remote Access API
  • 30.
    Demo 3: SlackChatbot + Blue Ocean API
  • 31.
    What Is BlueOcean API? • Used by Blue Ocean UX • Private API • JSON Web Token • Pipeline, run, queue, log • User, organisation, SCM
  • 33.
  • 34.
    What’s Next? • Upgradeto OpenAPI 3.0 • JWT authentication support • Folder support • Future of Jenkins API?
  • 35.
  • 36.
    Resources • Swaggy Jenkins- https://github.com/cliffano/swaggy- jenkins • Nestor - https://github.com/cliffano/nestor • Jenkins api.ai Demo - https://github.com/cliffano/jenkins- apiai-demo • Jenkins Slack Demo - https://github.com/cliffano/jenkins- slack-demo • Jenkins Remote Access API - https://wiki.jenkins.io/display/ jenkins/remote+access+api • Jenkins Blue Ocean API - https://github.com/jenkinsci/ blueocean-plugin/tree/master/blueocean-rest
  • 37.