You've already forked jenkins-lib
forked from jenkins/jenkins-lib
Merge pull request #36 from firstBitSemenovskaya/feature-compute-repo-slug
This commit is contained in:
@@ -107,9 +107,9 @@ pipeline1C()
|
||||
* Исходники конфигурации ожидаются в каталоге `src/cf` (`srcDir`).
|
||||
* Формат исходников - выгрузка из Конфигуратора (`sourceFormat`).
|
||||
* Ветка по умолчанию (для комбинированного режима загрузки конфигурации) - "main" (`defaultBranch`).
|
||||
* TODO: Имена "секретов" (jenkins credentials, `secrets`) по умолчанию высчитываются как `GROUP_REPO_KEY`, где `GROUP` и `REPO` - это группа проектов и имя проектов (например, `firstBitSemenovskaya` и `jenkins-lib`), а `KEY` - ключ секрета:
|
||||
* `STORAGE_PATH` - путь к хранилищу конфигурации (`secrets` -> `storagePath`);
|
||||
* `STORAGE_USER` - параметры авторизации в хранилище вида "username with password" (`secrets` -> `storage`).
|
||||
* Имена "секретов" (jenkins credentials, `secrets`) по умолчанию высчитываются из пути к git-репозиторию (без учета домена, с заменой `/` на `_`) с прибавлением ключа секрета. Например, для репозитория https://github.com/firstBitSemenovskaya/jenkins-lib секрет с адресом хранилища будет выглядеть как `firstBitSemenovskaya_jenkins-lib_STORAGE_PATH`. Ключи секретов:
|
||||
* `STORAGE_PATH` - путь к хранилищу конфигурации (для `secrets` -> `storagePath`);
|
||||
* `STORAGE_USER` - параметры авторизации в хранилище вида "username with password" (для `secrets` -> `storage`).
|
||||
* Все "шаги" по умолчанию выключены (`stages`).
|
||||
* Если в корне репозитория существует файл `packagedef`, то в шагах, работающих с информационной базой, будет выполнена попытка установки локальных зависимостей средствами `opm`.
|
||||
* Если после установки локальных зависимостей в каталоге `oscript_modules/bin` сушествует файл `vrunner`, то для выполнения команд работы с информационной базой будет использоваться он, а не глобально установленный `vrunner` из `PATH`.
|
||||
|
@@ -29,6 +29,12 @@ interface IStepExecutor {
|
||||
|
||||
void tool(String toolName)
|
||||
|
||||
def withCredentials(List bindings, Closure body)
|
||||
|
||||
def string(String credentialsId, String variable)
|
||||
|
||||
def usernamePassword(String credentialsId, String usernameVariable, String passwordVariable)
|
||||
|
||||
void withSonarQubeEnv(String installationName, Closure body)
|
||||
|
||||
EnvironmentAction env()
|
||||
|
@@ -69,6 +69,23 @@ class StepExecutor implements IStepExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
def withCredentials(List bindings, Closure body) {
|
||||
steps.withCredentials(bindings) {
|
||||
body()
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
def string(String credentialsId, String variable) {
|
||||
return steps.string(credentialsId: credentialsId, variable: variable)
|
||||
}
|
||||
|
||||
@Override
|
||||
def usernamePassword(String credentialsId, String usernameVariable, String passwordVariable) {
|
||||
return steps.usernamePassword(credentialsId: credentialsId, usernameVariable: usernameVariable, passwordVariable: passwordVariable)
|
||||
}
|
||||
|
||||
@Override
|
||||
EnvironmentAction env() {
|
||||
return steps.env
|
||||
|
@@ -7,6 +7,8 @@ import com.fasterxml.jackson.annotation.JsonPropertyDescription
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
class Secrets implements Serializable {
|
||||
|
||||
public static final String UNKNOWN_ID = "UNKNOWN_ID"
|
||||
|
||||
@JsonPropertyDescription("Путь к хранилищу конфигурации")
|
||||
String storagePath
|
||||
|
||||
|
74
src/ru/pulsar/jenkins/library/steps/InitFromStorage.groovy
Normal file
74
src/ru/pulsar/jenkins/library/steps/InitFromStorage.groovy
Normal file
@@ -0,0 +1,74 @@
|
||||
package ru.pulsar.jenkins.library.steps
|
||||
|
||||
import com.cloudbees.groovy.cps.NonCPS
|
||||
import org.jenkinsci.plugins.workflow.support.actions.EnvironmentAction
|
||||
import ru.pulsar.jenkins.library.IStepExecutor
|
||||
import ru.pulsar.jenkins.library.configuration.JobConfiguration
|
||||
import ru.pulsar.jenkins.library.configuration.Secrets
|
||||
import ru.pulsar.jenkins.library.ioc.ContextRegistry
|
||||
import ru.pulsar.jenkins.library.utils.Logger
|
||||
import ru.pulsar.jenkins.library.utils.VRunner
|
||||
import ru.pulsar.jenkins.library.utils.VersionParser
|
||||
|
||||
import static ru.pulsar.jenkins.library.configuration.Secrets.UNKNOWN_ID
|
||||
|
||||
class InitFromStorage implements Serializable {
|
||||
|
||||
final static REPO_SLUG_REGEXP = ~/(?m)^(?:[^:\/?#\n]+:)?(?:\/+[^\/?#\n]*)?\/?([^?\n]*)/
|
||||
|
||||
private final JobConfiguration config
|
||||
|
||||
InitFromStorage(JobConfiguration config) {
|
||||
this.config = config
|
||||
}
|
||||
|
||||
def run() {
|
||||
IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()
|
||||
|
||||
Logger.printLocation()
|
||||
|
||||
if (config.infobaseFromFiles()) {
|
||||
Logger.println("init infoBase from storage is disabled")
|
||||
return
|
||||
}
|
||||
|
||||
steps.installLocalDependencies()
|
||||
|
||||
String storageVersion = VersionParser.storage()
|
||||
String storageVersionParameter = storageVersion == "" ? "" : "--storage-ver $storageVersion"
|
||||
|
||||
EnvironmentAction env = steps.env();
|
||||
String repoSlug = computeRepoSlug(env.GIT_URL)
|
||||
|
||||
Secrets secrets = config.secrets
|
||||
|
||||
String storageCredentials = secrets.storage == UNKNOWN_ID ? repoSlug + "_STORAGE_USER" : secrets.storage
|
||||
String storagePath = secrets.storagePath == UNKNOWN_ID ? repoSlug + "_STORAGE_PATH" : secrets.storagePath
|
||||
|
||||
steps.withCredentials([
|
||||
steps.usernamePassword(
|
||||
storageCredentials,
|
||||
'RUNNER_STORAGE_USER',
|
||||
'RUNNER_STORAGE_PWD'
|
||||
),
|
||||
steps.string(
|
||||
storagePath,
|
||||
'RUNNER_STORAGE_NAME'
|
||||
)
|
||||
]) {
|
||||
String vrunnerPath = VRunner.getVRunnerPath()
|
||||
steps.cmd "$vrunnerPath init-dev --storage $storageVersionParameter --ibconnection \"/F./build/ib\""
|
||||
}
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
private static String computeRepoSlug(String text) {
|
||||
def matcher = text =~ REPO_SLUG_REGEXP
|
||||
String repoSlug = matcher != null && matcher.getCount() == 1 ? matcher[0][1] : ""
|
||||
if (repoSlug.endsWith(".git")) {
|
||||
repoSlug = repoSlug[0..-5]
|
||||
}
|
||||
repoSlug = repoSlug.replace('/', '_')
|
||||
return repoSlug
|
||||
}
|
||||
}
|
@@ -1,28 +1,10 @@
|
||||
import ru.pulsar.jenkins.library.configuration.JobConfiguration
|
||||
import ru.pulsar.jenkins.library.utils.VRunner
|
||||
import ru.pulsar.jenkins.library.utils.VersionParser
|
||||
import ru.pulsar.jenkins.library.ioc.ContextRegistry
|
||||
import ru.pulsar.jenkins.library.steps.InitFromStorage
|
||||
|
||||
def call(JobConfiguration jobConfiguration) {
|
||||
def call(JobConfiguration config) {
|
||||
ContextRegistry.registerDefaultContext(this)
|
||||
|
||||
printLocation()
|
||||
|
||||
installLocalDependencies();
|
||||
|
||||
def storageVersion = VersionParser.storage()
|
||||
def storageVersionParameter = storageVersion == "" ? "" : "--storage-ver $storageVersion"
|
||||
|
||||
withCredentials([
|
||||
usernamePassword(
|
||||
credentialsId: jobConfiguration.secrets.storage,
|
||||
passwordVariable: 'STORAGE_PSW',
|
||||
usernameVariable: 'STORAGE_USR'
|
||||
),
|
||||
string(
|
||||
credentialsId: jobConfiguration.secrets.storagePath,
|
||||
variable: 'STORAGE_PATH'
|
||||
)
|
||||
]) {
|
||||
String vrunnerPath = VRunner.getVRunnerPath();
|
||||
cmd "$vrunnerPath init-dev --storage --storage-name $STORAGE_PATH --storage-user $STORAGE_USR --storage-pwd $STORAGE_PSW $storageVersionParameter --ibconnection \"/F./build/ib\""
|
||||
}
|
||||
def initFromStorage = new InitFromStorage(config)
|
||||
initFromStorage.run()
|
||||
}
|
Reference in New Issue
Block a user