DEV Community

Cover image for Deploy Jenkins job from the command line and chrome notification for job result
Tung Nguyen
Tung Nguyen

Posted on

Deploy Jenkins job from the command line and chrome notification for job result

Reason:

  • Current my daily tasks are:
    1. Develop feature
    2. Create a git merge request
    3. Create a git tag
    4. Go to Jenkins site and deploy to a specify env and git tag above
    5. Wait for Jenkins build result
  • So, I think I can make the process at step 4 and 5 more automatic

Solution:

  • A script for deploy Jenkins from the command line
    • So we no need switch to Jenkins page, now you can do everything on you IDE
  • A chrome extension for notifying when build success
    • Another solution is set up a webhook for Jenkins so it can send the result to Slack or Mattermost group. But I think it still makes spam for me, I just want to notify on some projects.

Preconditions:

  • You must have Jenkins username and API token
    • API token get at Configure tab on the account info page

Script for deploy Jenkins from the command line

  • It uses Jenkins API for send deploy request
  • Basically, all of it is do this command
curl -v -X POST https://jenkins.com/job/admin-apibuild \
  --user yourusername:yourapitoken \
  --data-urlencode json='{"parameter": [{"name":"Environment", "value":"test"}, {"name":"COMMIT", "value":"dev"}]}'
  • Value of parameter depend on the config of your Jenkins job
  • I wrapper above curl command to Javascript file, so you need Node to run
  • We can run a command like node scripts/deploy.js dev v1.1.1
    • You can custom to correct with your Jenkins config
  • Source code at https://github.com/tungnt620/jenkins-auto

A chrome extension for notifying when build success

How it works

  • We have a monitor server which uses for interval fetch status of jobs
    • We choose jobs to want to monitor
  • This monitor server also serves an API get notifies which used by chrome ext
  • Chrome ext interval fetch notifies from the monitor server and displays it.

Alt Text

Setup

The end

  • I think one way to boot productivity is to avoid context switch as much as possible.
  • If you have any other ways, solutions please share with us

Top comments (0)