Skip to content

Latest commit

 

History

History
82 lines (58 loc) · 2.03 KB

File metadata and controls

82 lines (58 loc) · 2.03 KB

Starting and configuring a Nexus server

Purpose

Especially when demonstrating the Plugin Catalog functionality, a Nexus server is needed. The Plugin Catalog also requires a special Maven2 proxy repository to be configured. This example shows how to start a Nexus server (as a Docker container) et to configure the needed repository via the Nexus CLI.

The example directory contains the various command files in the directory example as well as a working Ansible role in the ansible-role directory.

Example directory inventory

Docker compose

nexus_docker-compose.yml
version: '3'

services:

  nexus:
    # The version must be pinned: later version have random default
    # password which make automation more complicated.
    image: sonatype/nexus3:3.16.2
    ports:
      - "8081:8081"
    volumes:
      - nexus-data:/nexus-data

volumes:

  nexus-data:
    driver: local

Note the pinned image version.

Starting and stopping the Nexus container

start_nexus.sh
#!/usr/bin/env bash

docker-compose up -d
stop_nexus.sh
#!/usr/bin/env bash

docker-compose down

Configuring the proxy repository

The configuration is done with a groovy script that is loaded and then executed via the Nexus REST API. The bash scripts are expected to run on the machine hosting the Docker containers (curl loacalhost).

loading the configuration groovy script on the Nexus server

load_nexus_script.sh
#!/usr/bin/env bash

curl -X POST -u admin:admin123 --header 'Content-Type: application/json' \
    http://127.0.0.1:8081/service/rest/v1/script \
    -d '{"name":"jenkins","type":"groovy","content":"repository.createMavenProxy('\''jenkins'\'','\''https://repo.cloudbees.com/content/repositories/dev-connect/'\'')"}'

Executing the loaded groovy script

execute_nexus_script.sh
#!/usr/bin/env bash

curl -X POST -u admin:admin123 --header "Content-Type: text/plain" 'http://127.0.0.1:8081/service/rest/v1/script/jenkins/run'