The coalesce macro should work with built-in dotnet new parameters
See original GitHub issueI’m trying to use the value provided via the “output” parameter (-o) to replace a path that’s referenced in one of my source files. That file happens to be a Jenkinsfile that needs to know where a sln file is located in order to build it. The jenkinsfile will live in the same directory as my sln.
When I don’t specify a value, I’m fine with falling back to my default (since the developer knows to scaffold the solution in a directory which matches the default).
My ultimate goal is to enable a developer to run the template engine, check in the source, and build the application through jenkins via a jenkinsfile.
Using the code below, you’ll notice that you ALWAYS get the default value when you invoke the template to generated the transformed Jenkinsfile. I’m unaware of another way to do this (tried using an evaluate and also tried using “target” instead of “output”).
Am I missing something or is this just a gap?
Here’s the sample template.json
{
"$schema": "http://json.schemastore.org/template",
"author": "Test",
"classifications": [
"Web",
"WebAPI"
],
"name": "TEST ASP.NET Core Web API Solution",
"identity": "TEST.WebApi.SolutionTemplate",
"shortName": "test-webapi-sln",
"sourceName": "WebApiTemplate",
"preferNameDirectory": true,
"tags": {
"language": "C#"
},
"primaryOutputs": [
{
"path": "WebApiTemplate.sln"
}
],
"symbols": {
"DefaultSourceDirectory": {
"type": "generated",
"generator": "constant",
"parameters": {
"value": "src"
}
},
"SourceDirectoryReplacer": {
"type": "generated",
"generator": "coalesce",
"parameters": {
"sourceVariableName": "output",
"fallbackVariableName": "DefaultSourceDirectory"
},
"replaces": "templates/test-webapi-sln"
}
}
}
And the Jenkinsfile which it works on
pipeline {
agent none
options {
skipDefaultCheckout true
}
stages {
stage('Compile and test') {
agent {
label 'dotnet-2.2'
}
steps {
checkout scm
stash 'source'
dir("$WORKSPACE/templates/test-webapi-sln"){
echo 'Building WebApiTemplate.sln...'
sh 'dotnet build WebApiTemplate.sln'
echo 'Running unit tests...'
sh 'dotnet test UnitTests/test.WebApiTemplate.UnitTests.csproj --no-build'
}
}
}
stage('Build docker image') {
agent {
label 'docker'
}
steps {
unstash 'source'
dir("$WORKSPACE/templates/test-webapi-sln"){
sh 'DOCKER_REGISTRY=072100331905.dkr.ecr.us-west-2.amazonaws.com/ IMAGE_VERSION=0.0.0.$BUILD_NUMBER docker-compose build'
}
}
}
stage('Login to ECR') {
agent {
label 'aws-cli'
}
steps {
echo 'Generate script to enable docker-compose push to ECR'
sh 'aws ecr get-login --no-include-email --region us-west-2 > docker-login.sh'
sh 'chmod +x docker-login.sh'
stash includes: 'docker-login.sh', name: 'docker-login'
}
}
stage('Publish docker image') {
agent {
label 'docker'
}
steps {
unstash 'docker-login'
sh './docker-login.sh'
unstash 'source'
dir("$WORKSPACE/templates/test-webapi-sln"){
sh 'DOCKER_REGISTRY=072100331905.dkr.ecr.us-west-2.amazonaws.com/ IMAGE_VERSION=0.0.0.$BUILD_NUMBER docker-compose push'
}
}
}
}
}
When I run dotnet new -o output
, I’d expect that templates/test-webapi-sln
would be replaced with output
, but instead, it is replaced with src
(the default value in the coalesce macro).
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (7 by maintainers)
Top GitHub Comments
We have discussed this internally and found the concerns valid. We want to extend this to other useful built-in parameters such as fullOutputPath, hostIdentifier, hostVersion etc. For the time being, we are aiming for .NET 7.
Update on this: it is already possible to use
HostIdentifier
andHostVersion
(fordotnet new
) via bind symbols, however output path is still not accessible. AddingoutputPath
as implicit variable (asname
for--name
) has to be considered. At the moment there is no timeline for that unfortunately.