# JnsCLI is a command-line tool for Jenkins, allowing you to manage jobs, builds, and configurations directly from the terminal.

JnsCLI is a command-line interface for Jenkins, the popular CI/CD automation server. This tool allows you to interact with your Jenkins server directly from the command line, making it easier to manage jobs, builds, and server configurations without the need for the web interface.

## Table of Contents

* [Quick Start (Installation from Binary)](https://github.com/mirum8/jnscli#quick-start-installation-from-binary)
    
* [Manual Compilation](https://github.com/mirum8/jnscli#manual-compilation)
    
* [Features](https://github.com/mirum8/jnscli#features)
    
* [Usage](https://github.com/mirum8/jnscli#usage)
    
* [Commands](https://github.com/mirum8/jnscli#commands)
    
    * [List Jenkins Jobs](https://github.com/mirum8/jnscli#list-jenkins-jobs)
        
    * [Run a Job](https://github.com/mirum8/jnscli#run-a-job)
        
    * [Abort](https://github.com/mirum8/jnscli#abort)
        
    * [Connect](https://github.com/mirum8/jnscli#connect)
        
    * [Alias](https://github.com/mirum8/jnscli#alias)
        
    * [Info](https://github.com/mirum8/jnscli#info)
        
* [Contributing](https://github.com/mirum8/jnscli#contributing)
    
* [License](https://github.com/mirum8/jnscli#license)
    

## Quick Start (Installation from Binary)

Download the binary for your platform:

```plaintext
# for x86-64
wget -O jns-0.0.2-amd64 https://github.com/mirum8/jnscli/releases/download/v0.0.2/jns-0.0.2-amd64 \
&& chmod +x jns-0.0.2-amd64 && mkdir -p $HOME/.local/bin/ \
&& mv jns-0.0.2-amd64 $HOME/.local/bin/jns

# for ARM (Apple M1)
wget -O jns-0.0.2-arm64 https://github.com/mirum8/jnscli/releases/download/v0.0.2/jns-0.0.2-arm64 \
&& chmod +x jns-0.0.2-arm64 && mkdir -p $HOME/.local/bin/ \
&& mv jns-0.0.2-arm64 $HOME/.local/bin/jns
```

Add the binary to your PATH:

```plaintext
# for bash
echo "export PATH=\$PATH:$HOME/.local/bin/" >> $HOME/.bashrc && source $HOME/.bashrc
# for zsh
echo "export PATH=\$PATH:$HOME/.local/bin/" >> $HOME/.zshrc && source $HOME/.zshrc
```

Connect to your Jenkins server. You will be prompted to enter the server URL, username, and token:

```plaintext
jns connect
```

List Jenkins jobs:

```plaintext
jns list
```

Run a job:

```plaintext
jns build <jobName>
```

## Manual Compilation

### Prerequisites

* GraalVM JDK 21
    

### Steps

```plaintext
git clone https://github.com/mirum8/jnscli.git \
&& cd jnscli \
&& ./mvnw clean native:compile -Pnative \
&& mkdir -p $HOME/.local/bin/ \
&& mv target/jns $HOME/.local/bin/jns
```

Add the binary to your PATH:

```plaintext
# for bash
echo "export PATH=\$PATH:$HOME/.local/bin/" >> $HOME/.bashrc && source $HOME/.bashrc
# for zsh
echo "export PATH=\$PATH:$HOME/.local/bin/" >> $HOME/.zshrc && source $HOME/.zshrc
```

## Features

* Get a list of jobs
    
* Build a job with parameters
    
* Get information about a job and its builds
    
* Abort a running job
    
* Manage job aliases
    

## Usage

Start the CLI application and use the available commands to interact with your Jenkins server.

## Commands

### List Jenkins Jobs

List all jobs on the Jenkins server:

```plaintext
jns list
```

[![List jobs](https://github.com/mirum8/jnscli/raw/main/casts/list.gif align="left")](https://github.com/mirum8/jnscli/blob/main/casts/list.gif)

List jobs in a specific folder:

```plaintext
jns list <folder>
```

### Run a Job

Run a job on the Jenkins server:

```plaintext
jns build <jobId|jobName> [-p, --params <key=value>...] [-q, --quiet] [-l, --log]
```

[![Build job](https://github.com/mirum8/jnscli/raw/main/casts/build.gif align="left")](https://github.com/mirum8/jnscli/blob/main/casts/build.gif)

You can also use an ID number (prefixed by '%') from the 'list' output to start a job:

If the job already started, you can abort the previous build and start a new one (or cancel the new build):

Options:

* `-q, --quiet`: Run the job in quiet mode, suppressing the progress bar.
    
* `-l, --log`: Display the build log during running job.
    
* `-p, --params <key=value>`: Specify build parameters. If you don't specify required parameters, you will be prompted to enter them. To pass multiple parameters, use this flag multiple times. For example:
    
    ```plaintext
    jns build <jobId> \
      -p key1=value1  \
      -p key2=value2
    ```
    

### Abort

Abort a running job:

```plaintext
jns abort <jobId> [buildNumber]
```

### Connect

Connect to the Jenkins server:

```plaintext
jns connect
```

### Alias

Manage job aliases:

```plaintext
jns alias add <aliasName> <jobIdOrUrl> # Add an alias
jns alias rm <aliasName> # Remove an alias
jns alias ls # List all aliases
```

### Info

Get information about a job:

```plaintext
jns info <jobId> [options]
```

Options:

* `-b, --buildNumber`: Specify build number
    
* `-s, --includeSuccess`: Include successful builds
    
* `-f, --includeFailed`: Include failed builds
    
* `-r, --includeRunning`: Include running builds
    
* `-l, --limit`: Limit the number of builds (default: 3)
    
* `-m, --my-builds`: Show builds run by the current user
    

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the [MIT License](https://github.com/mirum8/jnscli/blob/main/LICENSE).
