ngen-japi
Jenkins API management CLI tool that also supports executing scripts from /usr/local/bin/japi-*.
Installation
Install from PyPI:
pip install ngen-japi
Or install from source:
pip install .
Usage
The japi command provides:
- Jenkins API management commands
- Script execution from bundled scripts
Version
Check the version:
japi --version
# or
japi -V
Login
Save Jenkins credentials for easy access:
japi login
The login command will:
- Prompt for Jenkins URL
- Ask for authentication method (username+token, username+password, or base64)
- Save credentials to
~/.ngen-japi/.env - Test the connection
After login, you can use Jenkins commands without setting environment variables each time.
Check Connection
Validate your Jenkins access and credentials:
japi check
The check command will:
- Test connection to Jenkins server
- Verify authentication credentials
- Display Jenkins version and basic info
- Show troubleshooting tips if connection fails
Examples:
japi login # Setup Jenkins credentials
japi check # Validate connection
japi --version # Check version
japi jobs # List all jobs
japi job my-job # Get job details
japi job --last-success # Get last 10 successful jobs
japi job --last-failure # Get last 10 failed jobs
japi build my-job # Trigger build
japi build my-job --param REF_NAME=develop REF_TYPE=branch # Build with parameters
japi build my-job --param=REF_NAME=develop --param=REF_TYPE=branch # Alternative format
japi get-xml my-job # Get job XML config
japi create my-job job.xml # Create job from XML
japi create my-job job.xml --force # Update existing job
japi delete my-job # Delete job (with confirmation)
japi delete my-job --force # Delete job without confirmation
japi plugin list # List all installed plugins
japi plugin list --format json --output plugins.json # Export to JSON
japi plugin list --format csv --output plugins.csv # Export to CSV
japi plugin install git # Install git plugin
japi plugin uninstall git # Uninstall git plugin
Jenkins API Management
Manage Jenkins jobs and builds using environment variables for authentication.
Environment Variables
Set the following environment variables for Jenkins authentication:
export JENKINS_URL="https://jenkins.example.com"
export JENKINS_USER="your-username"
export JENKINS_TOKEN="your-api-token"
Alternatively, you can use base64 encoded authentication:
export JENKINS_URL="https://jenkins.example.com"
export JENKINS_AUTH="base64-encoded-user:token"
Jenkins Commands
List all jobs:
japi jobs
Get job details:
japi job <job-name>
Get last 10 successful jobs:
japi job --last-success
Get last 10 failed jobs:
japi job --last-failure
Trigger a build:
japi build <job-name> [--param KEY=VALUE ...] or [--param=KEY=VALUE ...]
Options:
--param KEY=VALUE- Pass build parameters (can be used multiple times)--param=KEY=VALUE- Alternative format for build parameters
Examples:
japi build my-job
japi build my-job --param REF_NAME=develop REF_TYPE=branch
japi build my-job --param=REF_NAME=develop --param=REF_TYPE=branch
japi build my-job --param REF_NAME=develop --param=REF_TYPE=branch --param DEPLOY_ENV=staging
Get build console output:
japi log <job-name> <build-number>
Get job XML configuration:
japi get-xml <job-name>
Create or update job from XML:
japi create <job-name> <xml-file> [--force]
Options:
--force- Skip confirmation when updating existing job
Delete a job:
japi delete <job-name> [--force]
Options:
--force- Skip confirmation before deleting job
Note: Requires Jenkins permissions: Job/Create, Job/Update, Job/Configure, Job/Delete
List installed plugins:
japi plugin list [--format json|csv] [--output <file>]
Options:
--format json|csv- Export format (default: table)--output <file>- Output file (optional, defaults to stdout)
Examples:
japi plugin list
japi plugin list --format json
japi plugin list --format json --output plugins.json
japi plugin list --format csv --output plugins.csv
Install plugin(s):
japi plugin install <plugin1> [plugin2] ...
Examples:
japi plugin install git
japi plugin install git docker-workflow
Uninstall plugin(s):
japi plugin uninstall <plugin1> [plugin2] ...
Examples:
japi plugin uninstall git
japi plugin uninstall git docker-workflow
Note: Plugin operations require Jenkins permissions: Overall/Administer or Plugin/Install and Plugin/Uninstall
Credential Management
Manage Jenkins credentials stored in the global credentials store.
List all credentials:
japi cred list
Create a credential (interactive mode):
japi cred create
The interactive mode will prompt you to:
- Select credential type (Username/Password, Secret Text, SSH Key)
- Enter credential ID
- Enter description
- Enter type-specific fields (username, password, secret, private key, etc.)
Create a credential (non-interactive mode):
japi cred create --type <type> --id <id> [options...]
Supported credential types:
username_passwordorusername-password- Username and password credentialssecret_textorsecret-text- Secret text credentialsssh_keyorssh-key- SSH username with private key
Options for username_password:
--id <id>- Credential ID (required)--description <desc>- Description (optional)--username <user>- Username (required)--password <pass>- Password (required)--force- Overwrite existing credential
Options for secret_text:
--id <id>- Credential ID (required)--description <desc>- Description (optional)--secret <secret>- Secret text (required)--force- Overwrite existing credential
Options for ssh_key:
--id <id>- Credential ID (required)--description <desc>- Description (optional)--username <user>- Username (required)--private-key <key>- Private key content (required if not using file)--private-key-file <file>- Private key file path (required if not using key)--passphrase <phrase>- Passphrase for encrypted private key (optional)--force- Overwrite existing credential
Examples:
# Interactive mode
japi cred create
# Non-interactive: Username/Password
japi cred create --type username_password --id my-git-cred --username myuser --password mypass --description "Git credentials"
# Non-interactive: Secret Text
japi cred create --type secret_text --id my-token --secret "my-secret-token" --description "API token"
# Non-interactive: SSH Key
japi cred create --type ssh_key --id my-ssh-cred --username deploy --private-key-file ~/.ssh/id_rsa --description "Deployment SSH key"
# Overwrite existing credential
japi cred create --type username_password --id my-cred --username newuser --password newpass --force
Delete a credential:
japi cred delete <credential-id> [--force]
Options:
--force- Skip confirmation before deleting credential
Examples:
japi cred delete my-cred
japi cred delete my-cred --force
Backup all credentials:
japi cred backup [--file backup.json]
Restore credentials from backup:
japi cred restore [--file backup.json] [--force]
Options:
--file <file>- Path to the backup JSON file (default: jenkins_credentials_backup.json)--force- Overwrite existing credentials with the same ID during restore
Note: Credential operations require Jenkins permissions: Credentials/View, Credentials/Create, Credentials/Delete, or Overall/Administer
Script Execution
If you have a bundled script, you can execute it directly:
japi rancher --help
japi rancher version
The CLI will look for scripts in the bundled scripts directory.
How It Works
- When you run
japi {command}, the CLI dispatcher checks in this order:- Built-in commands: Jenkins management commands
- Scripts: Looks for a script at
/usr/local/bin/japi-{command}or bundled scripts
- If found, it executes the command with any additional arguments passed
- Scripts can be any executable file (bash, sh, Python, or binary)
Adding New Commands
Scripts
- Place a script in the
ngen_japi/scripts/directory with namejapi-{your-command} - Make sure it's executable:
chmod +x ngen_japi/scripts/japi-{your-command} - Use it with:
japi {your-command}
Development
Building the Package
python -m build
Publishing to PyPI
Menggunakan script otomatis:
./publish.sh --test # Publish ke Test PyPI
./publish.sh --publish # Publish ke PyPI production
Atau manual:
python -m build
python -m twine check dist/*
python -m twine upload dist/*
Untuk panduan lengkap, lihat PUBLISH.md.
Repository
License
MIT
Release files for ngen-japi 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ngen_japi-0.1.5.tar.gz | 28.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ngen_japi-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 55.1 kB
Release files / ngen_japi-0.1.5.tar.gz
| Download URL | ngen_japi-0.1.5.tar.gz |
|---|---|
| Size | 28.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5863eab7746d303e53d0f5a4e28585a09fe51946b0a2969634f164df7440ec15
|
|
BLAKE2b-256 checksum How to use checksums |
b20d1aa6e1617766250e1bb3b33e33dddc2aeaca5a1c324d7082d63781905dc1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Release files / ngen_japi-0.1.5-py3-none-any.whl
| Download URL | ngen_japi-0.1.5-py3-none-any.whl |
|---|---|
| Size | 26.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8dac30ce6e712ffe3b8e1b02fd2abede6dac012421d1c6017a71ba57847e5d51
|
|
BLAKE2b-256 checksum How to use checksums |
2d168aa7e29bc397e9b0f1499e0b3abb2d88c3ca52a65dd20d420fde72bc255d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|