Description
openedon Apr 2, 2019
I'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).