Skip to main content

A command-line interface for managing Jenkins jobs

Project description

Jenkins CLI Tool (jnks)

Release

A command-line interface for managing Jenkins jobs. Simple, fast, and easy to use.

Installation

pip install jnks-cli

Quick Start

  1. Configure Jenkins connection:
$ jnks config
Jenkins server host (e.g., https://jenkins.example.com): https://jenkins.company.com
Jenkins API token: your-api-token
Jenkins username: your-username
Testing connection...
Connection successful! Configuration saved to ~/.jenkins/config.yaml
  1. Initialize a job (in your project directory):
$ jnks init
Initialized job configuration in .jenkins.yaml
Found 3 parameters:
  BRANCH: $BRANCH
  ENV: staging
  DEBUG: true

Commands

Build (build)

Trigger a Jenkins job build.

# Basic build with parameters
$ jnks build BRANCH=main ENV=prod
Build #123 started

# Watch console output
$ jnks build --watch BRANCH=main
Build #124 started
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /workspace/my-job
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Checkout)
[Pipeline] checkout
...

# With debug logging
$ jnks build --debug BRANCH=main
2024-02-22 17:27:24 - DEBUG - Connecting to Jenkins server at https://jenkins.company.com
2024-02-22 17:27:24 - DEBUG - Build parameters: {"BRANCH": "main", "ENV": "staging"}
Build #125 started

Parameters in .jenkins.yaml marked with $ are required:

name: my-job
parameters:
  BRANCH: $BRANCH     # Required
  ENV: staging        # Optional with default
  DEBUG: true        # Optional with default

Console Output (console)

View build console output.

# View latest build
$ jnks console
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /workspace/my-job
...

# View specific build with watch
$ jnks console --watch --build 123
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /workspace/my-job
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Build)
...

Status (status)

View recent builds status.

$ jnks status
┌───────┬───────────────┬────────────┬─────────────────────┬──────────┐
│ Build  Name           Status      Started              Duration │
├───────┼───────────────┼────────────┼─────────────────────┼──────────┤
│ 125    my-job         SUCCESS     2024-02-22 17:27:24  45.2s    │
│ 124    my-job         FAILURE     2024-02-22 17:25:10  32.8s    │
│ 123    my-job         SUCCESS     2024-02-22 17:20:05  38.5s    │
│ 122    my-job         SUCCESS     2024-02-22 17:15:30  41.1s    │
│ 121    my-job         ABORTED     2024-02-22 17:10:15  12.3s    │
└───────┴───────────────┴────────────┴─────────────────────┴──────────┘

Open in Browser (open)

Open Jenkins job or build in your default browser.

# Open job page
$ jnks open
Opening https://jenkins.company.com/job/my-job in browser

# Open specific build
$ jnks open --build 123
Opening https://jenkins.company.com/job/my-job/123 in browser

Global Options

  • --debug: Enable debug logging (available for all commands)

Example debug output:

$ jnks status --debug
2024-02-22 17:27:24 - DEBUG - Connecting to Jenkins server at https://jenkins.company.com
2024-02-22 17:27:24 - DEBUG - SSL verification warnings disabled for HTTPS connection
2024-02-22 17:27:25 - DEBUG - Getting status for job my-job
2024-02-22 17:27:25 - DEBUG - Retrieved info for build #125
...

Configuration

The tool stores configuration in two locations:

  • Global: ~/.jenkins/config.yaml (Jenkins connection details)
host: https://jenkins.company.com
token: your-api-token
user: your-username
  • Local: .jenkins.yaml (Job-specific settings)
name: my-job
parameters:
  BRANCH: $BRANCH
  ENV: staging
  DEBUG: true

Error Handling

Common error messages and solutions:

  1. "Jenkins job not initialized":

    $ jnks build
    Jenkins job not initialized. Run 'jnks init' first.
    
    $ jnks init
    Initialized job configuration in .jenkins.yaml
    
  2. "Multiple builds are running":

    $ jnks console
    Multiple builds are running. Please select a build number:
    Build #125
    Build #124
    
    $ jnks console --build 125
    [Pipeline] Start of Pipeline...
    
  3. "No parameters provided":

    $ jnks build
    Error: No parameters provided. Required parameters:
      BRANCH: $BRANCH
    
    Example usage:
      jnks build BRANCH=main
    

License

MIT License - see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jnks_cli-1.0.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jnks_cli-1.0.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file jnks_cli-1.0.0.tar.gz.

File metadata

  • Download URL: jnks_cli-1.0.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.11

File hashes

Hashes for jnks_cli-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e807dc8616591355d097a1b86addf4ffc91ba599c35a5ed237d64882e9e24098
MD5 b2e0a40af4eb1d6e08059af8f476aa00
BLAKE2b-256 ab6019f0fadc9dc07f43f94cd7908b3bf98c87ac7473748362a57ad7d16e3178

See more details on using hashes here.

File details

Details for the file jnks_cli-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: jnks_cli-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.11

File hashes

Hashes for jnks_cli-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cac474a6ed6a4136e247a5b6be98128545d9a035d277bec1630daa8f42cf47c3
MD5 a0138331b47e21ccb171d7c8e68b6bb5
BLAKE2b-256 2e235437e88d5de18a2ec212010e9922871b2c124dc9e7c17c8d9bce91a8877a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page