Verwendung der Adoptium API in CI/CD-Pipelines

Wenn Ihre CI/CD-Plattform keine dedizierte Temurin-Einrichtungsaufgabe hat (wie GitHub Actions), können Sie die Adoptium API verwenden, um Eclipse Temurin direkt herunterzuladen, zu verifizieren und zu installieren. Diese Anleitung behandelt die Verwendung der API mit Shell-Skripten, die in jeder CI-Umgebung funktionieren, einschließlich Azure DevOps, GitLab CI, Jenkins, CircleCI und anderen.

API-Übersicht

Die Adoptium API bietet stabile URLs zum Herunterladen von Temurin-Binärdateien. Das allgemeine URL-Muster zum Herunterladen des neuesten GA-Releases ist:

https://api.adoptium.net/v3/binary/latest/{version}/ga/{os}/{arch}/{image_type}/hotspot/normal/eclipse

Wobei:

  • {version} — Java-Hauptversion (z.B. 8, 11, 17, 21, 25)

  • {os} — Betriebssystem: linux, windows, mac, alpine-linux, aix, solaris

  • {arch} — Architektur: x64, aarch64, arm, ppc64le, s390x, riscv64

  • {image_type}jdk oder jre

Note

Nicht alle Kombinationen sind verfügbar. Die API gibt HTTP 404 zurück, wenn kein Build für die angegebene Kombination existiert.

Verfügbare Versionen abfragen

Sie können ermitteln, welche Versionen verfügbar sind, einschließlich der aktuellen LTS:

# Die neueste LTS-Version abrufen
curl -s https://api.adoptium.net/v3/info/available_releases | jq '.most_recent_lts'

# Alle verfügbaren LTS-Releases auflisten
curl -s https://api.adoptium.net/v3/info/available_releases | jq '.available_lts_releases'

Eine Binärdatei herunterladen

Linux / macOS

#!/bin/bash
set -euo pipefail

JAVA_VERSION="25"
OS="linux"
ARCH="x64"
IMAGE_TYPE="jdk"

API_URL="https://api.adoptium.net/v3/binary/latest/${JAVA_VERSION}/ga/${OS}/${ARCH}/${IMAGE_TYPE}/hotspot/normal/eclipse"

# Download the binary (follows redirects)
FETCH_URL=$(curl -s -w %{redirect_url} "${API_URL}")
FILENAME=$(curl -OLs -w %{filename_effective} "${FETCH_URL}")

echo "Downloaded ${FILENAME}"

Windows (PowerShell)

$JavaVersion = "25"
$ApiUrl = "https://api.adoptium.net/v3/binary/latest/$JavaVersion/ga/windows/x64/jdk/hotspot/normal/eclipse"

$Response = Invoke-WebRequest -Uri $ApiUrl -MaximumRedirection 0 -ErrorAction SilentlyContinue
$DownloadUrl = $Response.Headers.Location
$FileName = [System.IO.Path]::GetFileName($DownloadUrl)

Invoke-WebRequest -Uri $DownloadUrl -OutFile $FileName
Write-Host "Downloaded $FileName"

Den Download überprüfen

Eclipse Temurin-Releases enthalten SHA-256-Prüfsummen und GPG-Signaturen neben jeder Binärdatei. Das Adoptium-Projekt empfiehlt dringend, Ihren Download in CI/CD-Pipelines zu verifizieren, um Integrität und Authentizität sicherzustellen.

SHA-256-Prüfsummenverifizierung

Die Prüfsummendatei ist unter derselben URL wie die Binärdatei mit angehängtem .sha256.txt verfügbar:

# Download and verify the checksum in one step
curl -Ls "${FETCH_URL}.sha256.txt" | sha256sum -c --status
echo "Checksum verified successfully"

Für PowerShell unter Windows:

# Download expected checksum
$ExpectedHash = (Invoke-WebRequest -Uri "$DownloadUrl.sha256.txt").Content.Split(" ")[0]

# Compute actual hash
$ActualHash = (Get-FileHash $FileName -Algorithm SHA256).Hash

if ($ExpectedHash -ne $ActualHash) {
    Write-Error "Checksum verification failed!"
    exit 1
}
Write-Host "Checksum verified successfully"

GPG-Signaturverifizierung

Temurin-Releases werden mit dem Adoptium GPG-Schlüssel signiert. Die Signaturdatei ist unter der Binärdatei-URL mit angehängtem .sig verfügbar:

# Import the Adoptium GPG public key
wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --import

# Download the signature file
curl -OLs "${FETCH_URL}.sig"

# Verify the signature
gpg --verify "${FILENAME}.sig" "${FILENAME}"

Vollständiges CI-Skript-Beispiel

Hier ist ein vollständiges Skript, das in jeder CI/CD-Pipeline verwendet werden kann und Eclipse Temurin herunterlädt, verifiziert und installiert:

#!/bin/bash
set -euo pipefail

# Configuration
JAVA_VERSION="${JAVA_VERSION:-25}"
OS="${OS:-linux}"
ARCH="${ARCH:-x64}"
IMAGE_TYPE="${IMAGE_TYPE:-jdk}"

API_URL="https://api.adoptium.net/v3/binary/latest/${JAVA_VERSION}/ga/${OS}/${ARCH}/${IMAGE_TYPE}/hotspot/normal/eclipse"

echo "Downloading Eclipse Temurin ${JAVA_VERSION} (${OS}/${ARCH})..."

# Download the binary
FETCH_URL=$(curl -s -w %{redirect_url} "${API_URL}")
FILENAME=$(curl -OLs -w %{filename_effective} "${FETCH_URL}")

# Verify SHA-256 checksum
echo "Verifying checksum..."
curl -Ls "${FETCH_URL}.sha256.txt" | sha256sum -c --status
echo "Checksum OK"

# Extract and configure
INSTALL_DIR="/opt/java/${JAVA_VERSION}"
mkdir -p "${INSTALL_DIR}"
tar xzf "${FILENAME}" -C "${INSTALL_DIR}" --strip-components=1

# Set environment variables
export JAVA_HOME="${INSTALL_DIR}"
export PATH="${JAVA_HOME}/bin:${PATH}"

echo "Eclipse Temurin ${JAVA_VERSION} installed to ${JAVA_HOME}"
java -version

Plattformspezifische Beispiele

Azure DevOps

steps:
  - script: |
      JAVA_VERSION="25"
      API_URL="https://api.adoptium.net/v3/binary/latest/${JAVA_VERSION}/ga/linux/x64/jdk/hotspot/normal/eclipse"
      FETCH_URL=$(curl -s -w %{redirect_url} "${API_URL}")
      FILENAME=$(curl -OLs -w %{filename_effective} "${FETCH_URL}")
      curl -Ls "${FETCH_URL}.sha256.txt" | sha256sum -c --status
      mkdir -p /opt/java && tar xzf "${FILENAME}" -C /opt/java --strip-components=1
      echo "##vso[task.setvariable variable=JAVA_HOME]/opt/java"
      echo "##vso[task.prependpath]/opt/java/bin"
    displayName: 'Install Eclipse Temurin 25'

GitLab CI

install-temurin:
  before_script:
    - |
      JAVA_VERSION="25"
      API_URL="https://api.adoptium.net/v3/binary/latest/${JAVA_VERSION}/ga/linux/x64/jdk/hotspot/normal/eclipse"
      FETCH_URL=$(curl -s -w %{redirect_url} "${API_URL}")
      FILENAME=$(curl -OLs -w %{filename_effective} "${FETCH_URL}")
      curl -Ls "${FETCH_URL}.sha256.txt" | sha256sum -c --status
      tar xzf "${FILENAME}" -C /opt --strip-components=1
      export JAVA_HOME=/opt
      export PATH="${JAVA_HOME}/bin:${PATH}"
      java -version

Jenkins (Scripted Pipeline)

node {
    stage('Install Temurin') {
        sh '''
            JAVA_VERSION="25"
            API_URL="https://api.adoptium.net/v3/binary/latest/$JAVA_VERSION/ga/linux/x64/jdk/hotspot/normal/eclipse"
            FETCH_URL=$(curl -s -w %{redirect_url} "$API_URL")
            FILENAME=$(curl -OLs -w %{filename_effective} "$FETCH_URL")
            curl -Ls "$FETCH_URL.sha256.txt" | sha256sum -c --status
            tar xzf "$FILENAME" -C /opt --strip-components=1
        '''
        env.JAVA_HOME = '/opt'
        env.PATH = "${env.JAVA_HOME}/bin:${env.PATH}"
    }
}
edit icon

Hilf uns, diese Dokumentation zu verbessern!

Alle Adoptium-Dokumentationen sind Open Source. Etwas falsch oder unklar?

Dokumentations-Autoren
gdams
Join our Slack channel to discuss and reach out to maintainers.Join Slack