Jenkins CLI (jcli)

repository·master·Indexed 19 days ago

https://github.com/jenkins-zh/jenkins-cli

A command-line tool and Go client library designed to simplify Jenkins management for administrators, plugin developers, and users. It provides interfaces for job management (triggering builds, retrieving logs and history), plugin administration, system configuration, and Jenkinsfile conversion between Groovy and JSON. Features include automated login for token retrieval, Jenkins WAR file downloads, agent label listing, and backup integration via the Thin Backup Plugin.

Tokens
42.6K
Snippets
214
Records
234
Agent score
64%

What's inside jenkins-cli

  1. Overview of Jenkins CLI features

    master

    Jenkins CLI (jcli) is designed for plugin developers, administrators, and general Jenkins users to manage Jenkins instances easily. Key features include:

    • Multi-instance management: Manage multiple Jenkins instances.
    • Plugin management: View lists, search, install, and upload plugins.
    • Job management: Search for jobs, trigger builds, and view logs.
    • Configuration as management: Manage via configuration.
    • Browser integration: Open Jenkins in your web browser.
    • System control: Restart Jenkins.
    • Connectivity: Support for connecting via proxies.
  2. Manage Jenkins jobs with jcli

    master

    You can interact with Jenkins jobs using the jcli job command group.

    • Search jobs: Use jcli job search <keyword> to find jobs matching a specific string.
    • Trigger a build: Use jcli job build "<folderName> <jobName>" to start a job. Use the -b flag for batch mode, which allows the command to finish immediately after triggering.
    • Watch logs: Use jcli job log "<jobIdentifier>" -w to watch the log output. The -w flag enables continuous output, and by default, this command outputs the logs for the most recent build.
    jcli job search input
    jcli job build "folderName jobName" -b
    jcli job log "zjproject zjproject-inputstep55" -w
  3. Download the developing version of jcli

    master

    To try the latest features, use the :dev tag. The binary paths within the container differ based on the target platform.

    # Linux development version
    jcli_id=$(docker create jenkinszh/jcli:dev) && sudo docker cp $jcli_id:/bin/linux/jcli .
    
    # Darwin (Mac) development version
    jcli_id=$(docker create jenkszh/jcli:dev) && sudo docker cp $jcli_id:/bin/darwin/jcli .
    
    # Windows development version
    jcli_id=$(docker create jenkszh/jcli:dev) && sudo docker cp $jcli_id:/bin/windows/jcli.exe .
  4. Install jcli via YUM (RPM)

    master

    To install jcli on RPM-based systems using YUM, add the jenkins-zh Bintray source repository to your system and then run the update and install commands.

    cat > bintray-jenkins-zh-rpm.repo <<EOF
    #bintraybintray-jenkins-zh-rpm - packages by jenkins-zh from Bintray
    [bintraybintray-jenkins-zh-rpm]
    name=bintray-jenkins-zh-rpm
    baseurl=https://dl.bintray.com/jenkins-zh/rpm
    gpgcheck=0
    repo_gpgcheck=0
    enabled=1
    EOF
    sudo mv bintray-jenkins-zh-rpm.repo /etc/yum.repos.d/
    sudo yum update
    yum install jcli
  5. Set a custom configuration path using JCLI_CONFIG

    master

    By default, the Jenkins CLI looks for its configuration file in a standard location. If you need to use a specific configuration file located elsewhere, you can override the default path by setting the JCLI_CONFIG environment variable. This is useful for managing multiple configurations or storing config files in non-standard directories.

    JCLI_CONFIG=/var/yourPath/jenkins-cli.yaml
  6. Install Jenkins CLI (jcli) on Windows

    master

    You can install jcli on Windows using scoop, choco, or by downloading the binary manually.

    Using Scoop:

    scoop install jcli

    Using Chocolatey:

    choco install jcli

    Manual Installation:

    1. Download the latest jcli-windows-amd64.zip from the GitHub release page.
    2. Uncompress the file.
    3. Copy the jcli directory into your system path.
    scoop install jcli
  7. Configure a proxy for a Jenkins server

    master

    If your Jenkins instance is behind a firewall and inaccessible directly, you can configure a proxy for a specific server in jcli.

    To add or modify proxy settings, use the jcli config edit command to open the configuration file. Within the configuration, locate the specific server under the jenkins_servers list and add the proxy and proxyAuth keys to that server's entry.

    • proxy: The URL of the proxy server (e.g., http://<proxy-ip>:<port>).
    • proxyAuth: The credentials for the proxy in the format username:password.
    jenkins_servers:
    - name: dev
      url: http://192.168.1.10
      username: admin
      token: 11132c9ae4b20edbe56ac3e09cb5a3c8c2
      proxy: http://192.168.10.10:47586
      proxyAuth: username:password
  8. Install Jenkins CLI (jcli) on Linux

    master

    To install jcli on Linux, download the latest amd64 tarball, extract it, and move the binary to your system path.

    curl -L https://github.com/jenkins-zh/jenkins-cli/releases/latest/download/jcli-linux-amd64.tar.gz|tar xzv
    sudo mv jcli /usr/local/bin/
  9. Install Jenkins CLI (jcli) on macOS

    master

    You can install jcli on macOS using brew or MacPorts.

    Using Homebrew:

    brew tap jenkins-zh/jcli
    brew install jcli

    Using MacPorts:

    sudo port install jenkins-cli

    To enable shell completion with MacPorts, add the +bash_completion or +zsh_completion flags during installation.

    brew tap jenkins-zh/jcli
    brew install jcli