You may want to try naming the variable something else besides "script" which is a pipeline variable (you use it right below). I might recommand PSSCRIPT, or something similar.
On Thu, Jan 18, 2018 at 9:14 AM Flavio Campana <[email protected]> wrote: > I've got a strange problem with a declarative pipeline and powershell, it > seems the script is never executed. > The script is in a managed file. > The pipeline: > > pipeline { > agent any > triggers { > pollSCM('H * * * *') > } > tools { > msbuild "DefaultMSBuild" > } > environment { > solution = 'Project.sln' > project = 'Project\\Project.csproj' > projectDir = 'Project\\Project' > key = credentials('proget-testauto-apikey') > } > stages { > stage('Build and test') { > steps { > echo "Getting version for ${env.projectDir}" > configFileProvider([configFile(fileId: > '52c08128-fa6f-4c79-8a43-ff4f6dd13dbd', variable: 'script')]) { > powershell script: "${script} -projecDir > ${env.projectDir}" > script { res = powershell script: "${script} -projecDir > ${env.projectDir}" > echo "results: ${res}" > } > } > echo 'Restore nugets..' > bat "%NUGET% restore Project.sln" > echo "Building solution : Project.sln" > script { > scanner = tool name: 'NewSonarScanner', type: > 'hudson.plugins.sonar.MsBuildSQRunnerInstallation' > props = readProperties text: '${res}' > withSonarQubeEnv('DefaultSonart') { > bat "${scanner}\\SonarQube.Scanner.MSBuild.exe > begin /k:Project /n:Project /v:${props.PackageVersion} > /d:sonar.host.url=%SONAR_HOST_URL% /d:sonar.login=%SONAR_AUTH_TOKEN% > /d:sonar.cs.nunit.reportsPaths=\"NTestResult.xml\" > /d:sonar.cs.opencover.reportsPaths=\"opencover.xml\" /d:sonar.verbose=true" > bat "\"${tool name: 'DefaultMSBuild', type: > 'msbuild'}\"\\msbuild.exe Project.sln /m /target:clean,build > /p:Configuration=Release" //;VisualStudioVersion=12.0 > nunitReturn = bat returnStatus: true, script: > "%OPENCOVER% -output:\"%WORKSPACE%\\opencover.xml\" -returntargetcode > -register:user -target:\"%NUNIT%\" > -targetargs:\"%WORKSPACE%\\Project.Tests\\bin\\Release\\Project.Tests.dll > -v --result=NTestResult.xml;format=nunit3 --work=%WORKSPACE%\" " > bat "${scanner}\\SonarQube.Scanner.MSBuild.exe end" > } > } > } > } > stage('Positive result') { > when { > expression { nunitReturn == 0 } > } > steps { > echo "Archiving Project" > archiveArtifacts artifacts: '**/bin/Release/**', > onlyIfSuccessful: true > bat "%NUGET% pack Project\\Project.csproj -Prop > Configuration=Release" > bat "%NUGET% push > Project\\Project.${props.PackageVersion}.nupkg -s %REPOTESTAUTO% ${key}" > > } > } > stage('Negative result'){ > when { > expression { nunitReturn > 0 } > } > steps { > script { currentBuild.result = "UNSTABLE" } > } > } > } > post { > > failure { > mail(from: "[email protected]", > to: "[email protected]", > subject: "Error in ${env.JOB_NAME}", > body: "See at ${env.BUILD_URL}") > } > > unstable { > mail(from: "[email protected]", > to: "[email protected]", > subject: "Test failed in ${env.JOB_NAME}", > body: "See at ${env.BUILD_URL}") > } > } > options { > // For example, we'd like to make sure we only keep 10 builds at a > time, so > // we don't fill up our storage! > buildDiscarder(logRotator(numToKeepStr:'20')) > timeout(time: 60, unit: 'MINUTES') > } > } > > the script: > param([Parameter(Mandatory=$true)][string]$projectDir) > $packageVersion = '' > Write-Output "Executed=True" > Write-Output > "PropFile=:$env:WORKSPACE\\$projectDir\\Properties\\AssemblyInfo.cs'" > $content = Get-Content ($env:WORKSPACE + '\\' + $projectDir + > '\\Properties\\AssemblyInfo.cs'); > foreach ($line in $content) > { > if ($line -match '\[assembly: > AssemblyVersion\("((\d+)\.?(\d*)\.?(\d*)?[\.-]?([\d\*]*)?([a-zA-Z]*)?(\d*?))"\)\]') > { > Write-Output "AssemblyFullVersion=$($Matches[1])" > Write-Output "AssemblyVersion=$($Matches[2]).$($Matches[3]).$($Matches[4])" > Write-Output "AssemblyMajor=$($Matches[2])" > Write-Output "AssemblyMinor=$($Matches[3])" > Write-Output "AssemblyRevision=$($Matches[4])" > Write-Output "AssemblyBuild=$($Matches[5])" > Write-Output "AssemblySuffix=$($Matches[6])" > Write-Output "AssemblyNumber=$($Matches[7])" > > if ($packageVersion -eq ''){ > $packageVersion = $Matches[1]; > } > } > elseif ($line -match '\[assembly: > AssemblyInformationalVersion\("((\d+)\.?(\d*)\.?(\d*)?[\.-]?([\d\*]*)?([a-zA-Z]*)?(\d*?))"\)\]') > { > Write-Output "AssemblyInfoFullVersion=$($Matches[1])" > Write-Output > "AssemblyInfoVersion=$($Matches[2]).$($Matches[3]).$($Matches[4])" > Write-Output "AssemblyInfoMajor=$($Matches[2])" > Write-Output "AssemblyInfoMinor=$($Matches[3])" > Write-Output "AssemblyInfoRevision=$($Matches[4])" > Write-Output "AssemblyInfoBuild=$($Matches[5])" > Write-Output "AssemblyInfoSuffix=$($Matches[6])" > Write-Output "AssemblyInfoNumber=$($Matches[7])" > $packageVersion = $Matches[1] > } > } > > Write-Output "PackageVersion=' + $packageVersion" > > This is wha i get in the logs > > Pipeline] configFileProviderprovisioning config files... > copy managed file [PSReadVersionNew] to > file:/R:/jenkins/workspace/Libraries/Project@2@tmp/config8563286677318369656tmp[Pipeline] > {[Pipeline] script[Pipeline] {[Pipeline] powershell > > [SigningLibrary@2] Running PowerShell script[Pipeline] echoresults: > [Pipeline] }[Pipeline] // script[Pipeline] }Deleting 1 temporary > files[Pipeline] // configFileProvider[Pipeline] echoRestore > nugets..[Pipeline] bat > > [SigningLibrary@2] Running batch script > > -- > You received this message because you are subscribed to the Google Groups > "Jenkins Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/jenkinsci-users/e693d2e9-759f-4a48-9a7b-0db5d341e65e%40googlegroups.com > <https://groups.google.com/d/msgid/jenkinsci-users/e693d2e9-759f-4a48-9a7b-0db5d341e65e%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Jenkins Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVe5bs0rBb-x%2Bt0nEpjngdU6nWN-XKT4m3Q6M91qtLbTUA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
