Call variable under a PS script as a parameter in Jenkins

Welcome Forums General PowerShell Q&A Call variable under a PS script as a parameter in Jenkins

This topic contains 1 reply, has 2 voices, and was last updated by

2 years ago.

  • Author
  • #63729

    Points: 0
    Rank: Member

    I have a config.ps1 script which has a variable "$versionNumber = "1.0.0"". I need enter the variable value of users choice and save the config.ps1 file. I need to do this task using Jenkins Parameter.

    My config.ps1 script.

    # Pack parameters used to create the .nupkg file.
    # Specify the Version Number to use for the NuGet package. If not specified, the version number of the assembly being packed will be used.
    # NuGet version number guidance: and the Semantic Versioning spec:
    # e.g. "" (use assembly's version), "1.2.3" (stable version), "1.2.3-alpha" (prerelease version).
    $versionNumber = "1.0.0"
    # Specify any Release Notes for this package. 
    # These will only be included in the package if you have a .nuspec file for the project in the same directory as the project file.
    $releaseNotes = ""
    # Specify a specific Configuration and/or Platform to only create a NuGet package when building the project with this Configuration and/or Platform.
    #   e.g. $configuration = "Release"
    #        $platform = "AnyCPU"
    $configuration = ""
    $platform = ""

    My approach-

    Get-Content c:\config.ps1 | ForEach-Object { $_ -replace "$versionNumber = "1.0.0"", "$versionNumber = "$env:version_number" }
  • #63730

    Points: 24
    Team Member
    Rank: Member

    You can use the Jenkins environment variable directly in the config script.

    $versionNumber = "$($env: environment_variable)"

The topic ‘Call variable under a PS script as a parameter in Jenkins’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort