DevOps/AQA
AUTH = "loginAndPassInBase64" GIT_URL = "https://bitbucket.ru" PROJECT = "yourProjectName" def getBranchesFromRepoName(repoName) { def branches = [] def endpoint = GIT_URL + "/rest/api/1.0/projects/${PROJECT}/repos/${repoName}/branches" def conn = new URL(endpoint).openConnection() conn.setRequestProperty("Authorization", "Basic ${AUTH}") def response = new groovy.json.JsonSlurper().parseText(conn.content.text) response.values.each { branches.add(it.displayId) } return branches } return getBranchesFromRepoName(repoName)
AUTH = "loginAndPassInBase64" NEXUS_URL = "http://nexus.ru:8080" ARTIFACT_GROUP = "your.group" ARTIFACT_NAME = "your.artifact.name" RELEASE_REPO = "Artifact_release" SNAPSHOT_REPO = "Snapshot_release" def getArtifactVersions() { def artifactVersions = [] def endpoint = NEXUS_URL + "/nexus/service/local/data_index?g=${ARTIFACT_GROUP}&a=${ARTIFACT_NAME}" def conn = new URL(endpoint).openConnection() conn.setRequestProperty("Authorization", "Basic ${AUTH}") def response = new XmlSlurper().parseText(conn.content.text) response.data.artifact.findAll {it.repoId == "${RELEASE_REPO}" || it.repoId == "${SNAPSHOT_REPO}"}.each { artifactVersions.add(it.version.text()) } return artifactVersions } return getArtifactVersions()
REGISTRY_URL = "https://registrynexus3.ru" PATH_TO_IMAGE = "your/path" IMAGE_NAME = "yourImageName" def getImageVersions() { def imageVersions = [] def endpoint = REGISTRY_URL + "/v2/${PATH_TO_IMAGE}/${IMAGE_NAME}/tags/list" def conn = new URL(endpoint).openConnection() def response = new groovy.json.JsonSlurper().parseText(conn.content.text) response.tags.each { imageVersions.add(it) } return imageVersions } return getImageVersions()
1. Получаем ветки из любого репозитория, который указан в Choice Parameter «repoName» (Active Choices Reactive Parameter “projectBranchName”):
AUTH = "loginAndPassInBase64"
GIT_URL = "https://bitbucket.ru"
PROJECT = "yourProjectName"
def getBranchesFromRepoName(repoName) {
def branches = []
def endpoint = GIT_URL + "/rest/api/1.0/projects/${PROJECT}/repos/${repoName}/branches"
def conn = new URL(endpoint).openConnection()
conn.setRequestProperty("Authorization", "Basic ${AUTH}")
def response = new groovy.json.JsonSlurper().parseText(conn.content.text)
response.values.each {
branches.add(it.displayId)
}
return branches
}
return getBranchesFromRepoName(repoName)
2. Получаем все версии необходимого артефакта из необходимых репозиториев (nexus2) в виде Active Choice Parameter «artifactVersion»:
AUTH = "loginAndPassInBase64"
NEXUS_URL = "http://nexus.ru:8080"
ARTIFACT_GROUP = "your.group"
ARTIFACT_NAME = "your.artifact.name"
RELEASE_REPO = "Artifact_release"
SNAPSHOT_REPO = "Snapshot_release"
def getArtifactVersions() {
def artifactVersions = []
def endpoint = NEXUS_URL + "/nexus/service/local/data_index?g=${ARTIFACT_GROUP}&a=${ARTIFACT_NAME}"
def conn = new URL(endpoint).openConnection()
conn.setRequestProperty("Authorization", "Basic ${AUTH}")
def response = new XmlSlurper().parseText(conn.content.text)
response.data.artifact.findAll {it.repoId == "${RELEASE_REPO}" || it.repoId == "${SNAPSHOT_REPO}"}.each {
artifactVersions.add(it.version.text())
}
return artifactVersions
}
return getArtifactVersions()
3. получаем все теги необходимого образа из docker registry (nexus 3), приведу пример, когда не требуется авторизация:
REGISTRY_URL = "https://registrynexus3.ru"
PATH_TO_IMAGE = "your/path"
IMAGE_NAME = "yourImageName"
def getImageVersions() {
def imageVersions = []
def endpoint = REGISTRY_URL + "/v2/${PATH_TO_IMAGE}/${IMAGE_NAME}/tags/list"
def conn = new URL(endpoint).openConnection()
def response = new groovy.json.JsonSlurper().parseText(conn.content.text)
response.tags.each {
imageVersions.add(it)
}
return imageVersions
}
return getImageVersions()