I ask this question already 
on 
https://stackoverflow.com/questions/51622150/how-to-use-jenkins-pipeline-method-parameters-in-powershell-script,
 
but maybe here is someone to help me.

I defined the following method in jenkins declarative pipeline, but I am 
not able to use the variables/output from "serverName", 
"archiveDestination" and "wwwrootPath". I tried already different ways but 
is does not work. The output from Write-Output is still "$serverName", 
${archiveDestination} and/or an empty variable.

How can I access the parameters from the serverdeployment-method in the 
Powershell script part?

def serverdeployment(serverName, archiveDestination, wwwrootPath) {
    powershell script: '''
    $servername = \'"$serverName"'
    $archivedestination = \'${archiveDestination}'
    $wwwrootpath = ${wwwrootPath}
    Write-Output $servername
    Write-Output $archivedestination
    Write-Output $wwwrootpath
    $pass = ConvertTo-SecureString -AsPlainText "XXXXX" -Force
    $cred = New-Object System.Management.Automation.PSCredential -ArgumentList 
"XXXXX",$pass
    $sessionOption = New-PSSessionOption -SkipCACheck -SkipCNCheck 
-SkipRevocationCheck
    $session = New-PSSession -ComputerName $serverName -UseSSL -Credential 
$cred -SessionOption $sessionOption
    Copy-Item $env:WORKSPACE\\* -Destination "$archiveDestination" -Filter 
*TEST* -Recurse -Force -Verbose -ToSession $session
    Invoke-Command -Session $session -ScriptBlock {iisreset /STOP}
    $filename = $env:JOB_NAME + "_TEST_" + $env:Version + "_" + 
$env:BUILD_NUMBER + "_wwwroot.7z"
    Invoke-Command -Session $session -ScriptBlock { & "C:\\Program 
Files\\7-Zip\\7z.exe" x $using:archiveDestination$using:filename -o$wwwrootpath 
-aoa >$null }
    Remove-Item "$wwwrootPath\\*\\_Cache\\*" -Recurse -Force
    Invoke-Command -Session $session -ScriptBlock {iisreset /START}
    Remove-PSSession $session
    Exit-PSSession
    '''
}


This method will be executed in steps part:

serverdeployment('myservername', 'C:\\data\\install\\', 
'C:\\inetpub\\wwwroot\\')


Thank you!


-- 
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/092fcb64-1fc8-47c1-98f9-9bcf7af3035f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to