mirror of
https://github.com/firstBitMarksistskaya/jenkins-lib.git
synced 2024-12-04 10:34:42 +02:00
Переопределение параметров git lfs
This commit is contained in:
parent
89acdc563a
commit
ff07c64314
@ -78,6 +78,7 @@ sharedLibrary {
|
||||
// TODO: retrieve downloaded plugin resource
|
||||
pluginDependencies {
|
||||
dependency("org.jenkins-ci.plugins", "pipeline-build-step", "2.12")
|
||||
dependency("org.jenkins-ci.plugins", "git", "4.4.4")
|
||||
dependency("org.6wind.jenkins", "lockable-resources", "2.7")
|
||||
dependency("ru.yandex.qatools.allure", "allure-jenkins-plugin", "2.28.1")
|
||||
val declarativePluginsVersion = "1.6.0"
|
||||
|
@ -3,7 +3,8 @@
|
||||
"srcDir": "src/cf",
|
||||
"secrets": {
|
||||
"storagePath": "UNKNOWN_ID",
|
||||
"storage": "UNKNOWN_ID"
|
||||
"storage": "UNKNOWN_ID",
|
||||
"lfs": "UNKNOWN_ID"
|
||||
},
|
||||
"stages": {
|
||||
"initSteps": false,
|
||||
@ -47,5 +48,9 @@
|
||||
"resultsTransform": {
|
||||
"removeSupport": false,
|
||||
"supportLevel": 0
|
||||
},
|
||||
"git": {
|
||||
"lfsPull": false,
|
||||
"lfsURI": ""
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,10 @@
|
||||
"storage" : {
|
||||
"type" : "string",
|
||||
"description" : "Данные авторизации в хранилище конфигурации"
|
||||
},
|
||||
"lfs" : {
|
||||
"type" : "string",
|
||||
"description" : "Данные авторизации для работы с LFS"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -143,6 +147,20 @@
|
||||
"description" : "Настройка фильтрации замечаний по уровню поддержки.\n 0 - удалить файлы на замке;\n 1 - удалить файлы на замке и на поддержке;\n 2 - удалить файлы на замке, на поддержке и снятые с поддержки.\n "
|
||||
}
|
||||
}
|
||||
},
|
||||
"git" : {
|
||||
"type" : "object",
|
||||
"id" : "urn:jsonschema:ru:pulsar:jenkins:library:configuration:GitSCMOptions",
|
||||
"description" : "Настройки git-репозитория",
|
||||
"properties" : {
|
||||
"lfsPull" : {
|
||||
"type" : "boolean",
|
||||
"description" : "Дополнительно выполнить git lfs pull"
|
||||
},
|
||||
"lfsURI" : {
|
||||
"type" : "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package ru.pulsar.jenkins.library
|
||||
|
||||
import hudson.plugins.git.GitSCM
|
||||
import hudson.scm.SCM
|
||||
import org.jenkinsci.plugins.workflow.support.actions.EnvironmentAction
|
||||
|
||||
interface IStepExecutor {
|
||||
@ -26,6 +28,10 @@ interface IStepExecutor {
|
||||
|
||||
EnvironmentAction env()
|
||||
|
||||
GitSCM scm()
|
||||
|
||||
void checkout(SCM scm)
|
||||
|
||||
void createDir(String path)
|
||||
|
||||
def withEnv(List<String> strings, Closure body)
|
||||
|
@ -1,5 +1,7 @@
|
||||
package ru.pulsar.jenkins.library
|
||||
|
||||
import hudson.plugins.git.GitSCM
|
||||
import hudson.scm.SCM
|
||||
import org.jenkinsci.plugins.workflow.support.actions.EnvironmentAction
|
||||
import ru.yandex.qatools.allure.jenkins.config.ResultsConfig
|
||||
|
||||
@ -63,6 +65,16 @@ class StepExecutor implements IStepExecutor {
|
||||
return steps.env
|
||||
}
|
||||
|
||||
@Override
|
||||
GitSCM scm() {
|
||||
return steps.scm
|
||||
}
|
||||
|
||||
@Override
|
||||
void checkout(SCM scm) {
|
||||
steps.checkout(scm)
|
||||
}
|
||||
|
||||
@Override
|
||||
void createDir(String path) {
|
||||
steps.createDir(path)
|
||||
|
@ -47,7 +47,8 @@ class ConfigurationReader implements Serializable {
|
||||
"bddOptions",
|
||||
"sonarQubeOptions",
|
||||
"syntaxCheckOptions",
|
||||
"resultsTransformOptions"
|
||||
"resultsTransformOptions",
|
||||
"gitSCMOptions"
|
||||
).toSet()
|
||||
|
||||
mergeObjects(baseConfiguration, configurationToMerge, nonMergeableSettings)
|
||||
|
@ -0,0 +1,23 @@
|
||||
package ru.pulsar.jenkins.library.configuration
|
||||
|
||||
import com.cloudbees.groovy.cps.NonCPS
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyDescription
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
class GitSCMOptions implements Serializable {
|
||||
|
||||
@JsonPropertyDescription("Дополнительно выполнить git lfs pull")
|
||||
boolean lfsPull
|
||||
|
||||
String lfsURI = ""
|
||||
|
||||
@Override
|
||||
@NonCPS
|
||||
String toString() {
|
||||
return "GitSCMOptions{" +
|
||||
"lfsPull=" + lfsPull +
|
||||
"lfsURI=" + lfsURI +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -40,6 +40,10 @@ class JobConfiguration implements Serializable {
|
||||
@JsonPropertyDescription("Настройки трансформации результатов анализа")
|
||||
ResultsTransformOptions resultsTransformOptions;
|
||||
|
||||
@JsonProperty("git")
|
||||
@JsonPropertyDescription("Настройки git-репозитория")
|
||||
GitSCMOptions gitSCMOptions;
|
||||
|
||||
@Override
|
||||
@NonCPS
|
||||
String toString() {
|
||||
@ -53,6 +57,7 @@ class JobConfiguration implements Serializable {
|
||||
", sonarQubeOptions=" + sonarQubeOptions +
|
||||
", syntaxCheckOptions=" + syntaxCheckOptions +
|
||||
", resultsTransformOptions=" + resultsTransformOptions +
|
||||
", gitSCMOptions=" + gitSCMOptions +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -13,12 +13,16 @@ class Secrets implements Serializable {
|
||||
@JsonPropertyDescription("Данные авторизации в хранилище конфигурации")
|
||||
String storage
|
||||
|
||||
@JsonPropertyDescription("Данные авторизации для работы с LFS")
|
||||
String lfs
|
||||
|
||||
@Override
|
||||
@NonCPS
|
||||
String toString() {
|
||||
return "Secrets{" +
|
||||
"storagePath='" + storagePath + '\'' +
|
||||
", storage='" + storage + '\'' +
|
||||
", lfs='" + lfs + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
package ru.pulsar.jenkins.library.steps
|
||||
|
||||
|
||||
import hudson.plugins.git.GitSCM
|
||||
import hudson.plugins.git.UserRemoteConfig
|
||||
import hudson.plugins.git.extensions.impl.GitLFSPull
|
||||
import ru.pulsar.jenkins.library.IStepExecutor
|
||||
import ru.pulsar.jenkins.library.configuration.JobConfiguration
|
||||
import ru.pulsar.jenkins.library.ioc.ContextRegistry
|
||||
@ -28,6 +32,8 @@ class EdtTransform implements Serializable {
|
||||
return
|
||||
}
|
||||
|
||||
doSCM()
|
||||
|
||||
def env = steps.env();
|
||||
|
||||
def workspaceDir = "$env.WORKSPACE/$WORKSPACE"
|
||||
@ -47,4 +53,64 @@ class EdtTransform implements Serializable {
|
||||
steps.zip(WORKSPACE, WORKSPACE_ZIP)
|
||||
steps.stash(WORKSPACE_ZIP_STASH, WORKSPACE_ZIP)
|
||||
}
|
||||
|
||||
private void doSCM() {
|
||||
|
||||
def gitSCMOptions = config.gitSCMOptions
|
||||
|
||||
if (!gitSCMOptions.lfsPull) {
|
||||
return
|
||||
}
|
||||
|
||||
IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()
|
||||
|
||||
def scm = steps.scm()
|
||||
|
||||
boolean needToCheckout = false
|
||||
needToCheckout = addLFS(scm, needToCheckout)
|
||||
scm = addLFSRemoteConfig(scm)
|
||||
|
||||
if (needToCheckout) {
|
||||
steps.checkout(scm)
|
||||
}
|
||||
}
|
||||
|
||||
private boolean addLFS(GitSCM scm, boolean needToCheckout) {
|
||||
GitLFSPull gitLFS = new GitLFSPull();
|
||||
def extensions = scm.getExtensions()
|
||||
if (!extensions.contains(gitLFS)) {
|
||||
needToCheckout = true
|
||||
extensions.add(gitLFS)
|
||||
}
|
||||
needToCheckout
|
||||
}
|
||||
|
||||
private GitSCM addLFSRemoteConfig(GitSCM scm) {
|
||||
def gitSCMOptions = config.gitSCMOptions
|
||||
|
||||
if (gitSCMOptions.lfsURI.isEmpty()) {
|
||||
return scm
|
||||
}
|
||||
|
||||
List<UserRemoteConfig> userRemoteConfigs = new ArrayList<>(scm.getUserRemoteConfigs())
|
||||
|
||||
def userRemoteConfig = userRemoteConfigs.find { it.url == gitSCMOptions.lfsURI }
|
||||
if (userRemoteConfig == null) {
|
||||
def credentialsId = config.secrets.lfs.isEmpty() ? null : config.secrets.lfs
|
||||
userRemoteConfig = new UserRemoteConfig(config.gitSCMOptions.lfsURI, null, null, credentialsId)
|
||||
userRemoteConfigs.add(0, userRemoteConfig)
|
||||
|
||||
scm = new GitSCM(
|
||||
userRemoteConfigs,
|
||||
scm.branches,
|
||||
scm.doGenerateSubmoduleConfigurations,
|
||||
scm.submoduleCfg,
|
||||
scm.browser,
|
||||
scm.gitTool,
|
||||
scm.extensions
|
||||
)
|
||||
}
|
||||
|
||||
return scm
|
||||
}
|
||||
}
|
||||
|
16
src/ru/pulsar/jenkins/library/steps/GitSCMExtension.groovy
Normal file
16
src/ru/pulsar/jenkins/library/steps/GitSCMExtension.groovy
Normal file
@ -0,0 +1,16 @@
|
||||
package ru.pulsar.jenkins.library.steps
|
||||
|
||||
import ru.pulsar.jenkins.library.configuration.JobConfiguration
|
||||
|
||||
class GitSCMExtension implements Serializable {
|
||||
|
||||
private final JobConfiguration config;
|
||||
|
||||
GitSCMExtension(JobConfiguration config) {
|
||||
this.config = config
|
||||
}
|
||||
|
||||
def run() {
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user