'How to include a function expression return value based on a script argument
I have a Jenkins monorepo pipeline for an Angular project using nrwl/nx.
I'm trying to use the npx nx affected:build command to build affected changes for the project apps / libs.
I need to populate the --baseHref based on a dynamic value based on the project name.
In the below example a APPS_BASE_HREF enumeration value based on the current project.name property.
It seems this approach does not work.
The function expression returns null, it does not resolve to the enumerator value.
I'm grooved up with trying! :)
The command resolves into :
nx run app2:build:development --baseHref=null
APPS_BASE_HREF = [
'app1': '/test/app1',
'app2': '/test/app2'
]
def getBaseHref(project){
return APPS_BASE_HREF.get(project);
}
pipeline {
agent any
environment { }
options {
buildDiscarder(logRotator(numToKeepStr: '5', artifactNumToKeepStr: '5'))
}
stages {
stage('build') {
steps {
sh "npx nx affected:build --base=origin/develop --base-href ${getBaseHref("{project.name}")}"
}
}
}
}
When modifying the getBaseHref function to :
def getBaseHref(project){
return project
}
The command does seem to recognize the project value, and resolves into :
nx run app2:build:development --baseHref=app2
Anybody ... any suggestions?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
