简体   繁体   中英

syntax to include Jenkins pipeline optional argument

I currently have a sample pipeline that works but in the Jenkins output does not return the confirmation that the script worked.


pipeline {
    agent any
     environment {
        CRED_APP_CATALOG =  credentials('id-app-tenant')
    }
    stages {
       
        stage('ConnectToApp'){
            
            steps {
                script{
                    pwsh '''
                        $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $env:CRED_APP_CATALOG_USR , $(convertto-securestring $env:CRED_APP_CATALOG_PSW -asplaintext -force)
                        Connect-PnPOnline -Url  $env:app_catalog_path -Credentials $cred 
                        Add-PnPApp -Path "./sharepoint/solution/samplesolution.sppkg" -Publish -Overwrite
                    '''

                }
               
            }
        }
       

    }
}

I know I need to add the returnStdout from pwsh script some where, but I cant seem to find the syntax any where.

This is the syntax to use:

pwsh returnStdout: true, script: '''
    $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $env:CRED_APP_CATALOG_USR , $(convertto-securestring $env:CRED_APP_CATALOG_PSW -asplaintext -force)
    Connect-PnPOnline -Url  $env:app_catalog_path -Credentials $cred 
    Add-PnPApp -Path "./sharepoint/solution/samplesolution.sppkg" -Publish -Overwrite
'''

Alternatively you may use parentheses:

pwsh( returnStdout: true, script: '''
    $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $env:CRED_APP_CATALOG_USR , $(convertto-securestring $env:CRED_APP_CATALOG_PSW -asplaintext -force)
    Connect-PnPOnline -Url  $env:app_catalog_path -Credentials $cred 
    Add-PnPApp -Path "./sharepoint/solution/samplesolution.sppkg" -Publish -Overwrite
''')

With both syntaxes, you may store the output in a variable for further processing:

def stdout = pwsh returnStdout: true, script: '''
    $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $env:CRED_APP_CATALOG_USR , $(convertto-securestring $env:CRED_APP_CATALOG_PSW -asplaintext -force)
    Connect-PnPOnline -Url  $env:app_catalog_path -Credentials $cred 
    Add-PnPApp -Path "./sharepoint/solution/samplesolution.sppkg" -Publish -Overwrite
'''

echo stdout

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM