added gradle/giteaMavenRepo.gradle for authenticating and adding gitea as repository for dependencies and publishing
This commit is contained in:
parent
6725a04d31
commit
852c14235d
@ -80,7 +80,7 @@
|
||||
|
||||
# drone does not support expanding vars in environment values, set defaults via bash
|
||||
if [[ -z "$CONTEXT_DIR" ]]; then CONTEXT_DIR="$DRONE_WORKSPACE_BASE"; fi
|
||||
if [[ -z "$DOCKERFILE" ]]; then DOCKERFILE="$DRONE_WORKSPACE_BASE/Dockerfile"; fi
|
||||
if [[ -z "$DOCKERFILE" ]]; then DOCKERFILE="$CONTEXT_DIR/Dockerfile"; fi
|
||||
|
||||
debug_log "CONTEXT_DIR=$CONTEXT_DIR"
|
||||
debug_log "DOCKERFILE=$DOCKERFILE"
|
||||
|
||||
@ -61,7 +61,7 @@
|
||||
|
||||
# drone does not support expanding vars in environment values, set defaults via bash
|
||||
if [[ -z "$CONTEXT_DIR" ]]; then CONTEXT_DIR="$DRONE_WORKSPACE_BASE"; fi
|
||||
if [[ -z "$DOCKERFILE" ]]; then DOCKERFILE="$DRONE_WORKSPACE_BASE/Dockerfile"; fi
|
||||
if [[ -z "$DOCKERFILE" ]]; then DOCKERFILE="$CONTEXT_DIR/Dockerfile"; fi
|
||||
|
||||
debug_log "CONTEXT_DIR=$CONTEXT_DIR"
|
||||
debug_log "DOCKERFILE=$DOCKERFILE"
|
||||
|
||||
61
gradle/GiteaMavenRepo.gradle
Normal file
61
gradle/GiteaMavenRepo.gradle
Normal file
@ -0,0 +1,61 @@
|
||||
def addGiteaRepository(RepositoryHandler handler, String giteaApiUrl, String organization, String token = null) {
|
||||
handler.maven {
|
||||
name "gitea-$organization"
|
||||
url = "${giteaApiUrl}/api/packages/${organization}/maven"
|
||||
setGiteaRepoAuth(it, token)
|
||||
}
|
||||
}
|
||||
|
||||
def addGiteaPublishingRepository(RepositoryHandler handler, String giteaApiUrl, String organization, String token = null) {
|
||||
handler.maven {
|
||||
name "gitea-$organization"
|
||||
url = "${giteaApiUrl}/api/packages/${organization}/maven"
|
||||
setGiteaRepoAuth(it, token)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add auth to repo, attempt to find token by first non-null:
|
||||
* - function argument "token"
|
||||
* - env var: CI_JOB_TOKEN
|
||||
* - env var: CI_REGISTRY_PASSWORD
|
||||
* - gradle project var: giteaPrivateToken
|
||||
* Throws exception if no auth token was found.
|
||||
*/
|
||||
def setGiteaRepoAuth(MavenArtifactRepository maven, String token = null) {
|
||||
|
||||
if (token != null) {
|
||||
maven.credentials(HttpHeaderCredentials) {
|
||||
name = 'Authorization'
|
||||
value = "token " + System.getenv("CI_JOB_TOKEN")
|
||||
}
|
||||
} else if (System.getenv("CI_JOB_TOKEN") != null) {
|
||||
maven.credentials(HttpHeaderCredentials) {
|
||||
name = 'Authorization'
|
||||
value = "token " + System.getenv("CI_JOB_TOKEN")
|
||||
}
|
||||
} else if (System.getenv("CI_REGISTRY_PASSWORD") != null) {
|
||||
maven.credentials(HttpHeaderCredentials) {
|
||||
name = 'Authorization'
|
||||
value = "token " + System.getenv("CI_REGISTRY_PASSWORD")
|
||||
}
|
||||
} else if (project.hasProperty("giteaPrivateToken")) {
|
||||
maven.credentials(HttpHeaderCredentials) {
|
||||
name = 'Authorization'
|
||||
value = "token " + giteaPrivateToken
|
||||
}
|
||||
} else {
|
||||
throw Exception("No gitea repository auth configured")
|
||||
}
|
||||
|
||||
maven.authentication {
|
||||
header(HttpHeaderAuthentication)
|
||||
}
|
||||
}
|
||||
|
||||
// Export methods by turning them into closures
|
||||
ext {
|
||||
setGiteaRepoAuth = this.&setGiteaRepoAuth
|
||||
addGiteaRepository = this.&addGiteaRepository
|
||||
addGiteaPublishingRepository = this.&addGiteaPublishingRepository
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user