1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-09-16 09:26:22 +02:00

Infer project name (#2119)

Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
This commit is contained in:
Daniel Kurzynski
2020-10-05 19:34:43 +02:00
committed by GitHub
parent ecbc2d4b0f
commit f5b19a79e4
2 changed files with 32 additions and 1 deletions

View File

@@ -30,7 +30,8 @@ def stashList(script, List stashes) {
def exclude = stash.excludes
if (stash?.merge == true) {
String lockName = "${script.commonPipelineEnvironment.configuration.stashFiles}/${stash.name}"
String lockingResourceGroup = script.commonPipelineEnvironment.projectName?:env.JOB_NAME
String lockName = "${lockingResourceGroup}/${stash.name}"
lock(lockName) {
unstash stash.name
echo "Stash content: ${name} (include: ${include}, exclude: ${exclude})"

View File

@@ -28,6 +28,10 @@ import static com.sap.piper.Prerequisites.checkScript
* If this is set to true, it is not required to provide the `buildTool` parameter in the `general` section of the pipeline configuration.
*/
'inferBuildTool',
/**
* Enables automatic inference from the build descriptor in case projectName is not configured.
*/
'inferProjectName',
/**
* Toggle for initialization of the stash settings for Cloud SDK Pipeline.
* If this is set to true, the stashSettings parameter is **not** configurable.
@@ -41,6 +45,10 @@ import static com.sap.piper.Prerequisites.checkScript
* Defines the main branch for your pipeline. **Typically this is the `master` branch, which does not need to be set explicitly.** Only change this in exceptional cases
*/
'productiveBranch',
/**
* Name of the project, e.g. used for the name of lockable resources.
*/
'projectName',
/**
* Defines the library resource containing stage/step initialization settings. Those define conditions when certain steps/stages will be activated. **Caution: changing the default will break the standard behavior of the pipeline - thus only relevant when including `Init` stage into custom pipelines!**
*/
@@ -122,6 +130,12 @@ void call(Map parameters = [:]) {
String buildTool = checkBuildTool(config)
script.commonPipelineEnvironment.projectName = config.projectName
if (!script.commonPipelineEnvironment.projectName && config.inferProjectName) {
script.commonPipelineEnvironment.projectName = inferProjectName(script, buildTool)
}
if (Boolean.valueOf(env.ON_K8S) && config.containerMapResource) {
ContainerMap.instance.initFromResource(script, config.containerMapResource, buildTool)
}
@@ -193,6 +207,22 @@ void call(Map parameters = [:]) {
}
}
private String inferProjectName(Script script, String buildTool) {
switch (buildTool) {
case 'maven':
def pom = script.readMavenPom file: 'pom.xml'
return "${pom.groupId}-${pom.artifactId}"
case 'npm':
Map packageJson = script.readJSON file: 'package.json'
return packageJson.name
case 'mta':
Map mta = script.readYaml file: 'mta.yaml'
return mta.ID
}
script.error "Cannot infer projectName. Project buildTool was none of the expected ones 'mta', 'maven', or 'npm'."
}
private String checkBuildTool(config) {
def buildDescriptorPattern = ''
String buildTool = config.buildTool