combine Gitlab CI with Gradle and System Environmental Variables

Viewed 589

I am trying to create a nice Pipeline for a little Project.

Setup:

  • Ubuntu 20.04 VM
  • (Test) Credentials stored in /etc/environment
  • (Test) Credentials stored in Gitlab's global Variables: Text
  • (Test) Credentials stored in Gitlab's project Variables: Text
  • Java 15 based Project with Gradle as Build-Management-Tool
  • Gitlab-CE (Dockerized)
  • Gitlab-Runner (Dockerized)
  • Artifactory (Dockerized)

Expected behavior / routine:

  1. Commit and Push Project / Trigger Gitlab Pipeline
  2. Gitlab builds project
  3. Gradle push to Artifactory using Credentials from Variables.

Content in /etc/environment:

root@<> ~ # cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
epeuUser="..."
epeuPassword="..."
epeuArtifactoryContextURL="https://<url>/artifactory"
epeuRepoKey="repo"


gitlab-ci.yml:

image: gradle:6.7.1-jre15

stages:
  - build

build:
  stage: build
  script: gradle --build-cache publish
  cache:
    key: "$CI_COMMIT_REF_NAME"
    policy: push
    paths:
      - build
      - .gradle

build.gradle:

plugins {
  id 'com.github.johnrengelman.shadow' version '6.1.0'
}

allprojects {

  tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
  }

  apply plugin: 'java-library'
  apply plugin: 'maven'
  apply plugin: 'maven-publish'
  apply plugin: 'com.github.johnrengelman.shadow'

  sourceCompatibility = '15'
  targetCompatibility = '15'

  repositories {
    mavenCentral()

    maven {
      url "${epeuArtifactoryContextURL}/${epeuRepoKey}/"
        credentials {
          username "${epeuUser}"
          password "${epeuPassword}"
      }
      metadataSources {
        mavenPom()
        gradleMetadata()
        artifact()
      }
    }

  }

  dependencies {
    compile group: 'com.google.inject', name: 'guice', version: '5.0.0-BETA-1'
  }

  publishing {
    repositories {
      maven {
        url "${epeuArtifactoryContextURL}/${epeuRepoKey}/"
          credentials {
            username "${epeuUser}"
            password "${epeuPassword}"
          }
        }
    }
    publications {
      gpr(MavenPublication) {
        from(components.java)
      }
    }
  }

}

Pipeline Result: Text

Any Ideas what i should do?

0 Answers
Related