Call variable under a PS script as a parameter in Jenkins

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Daniel Krebs Daniel Krebs 1 month, 2 weeks ago.

  • Author
    Posts
  • #63729
    Profile photo of kalyanbhave
    kalyanbhave
    Participant

    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: https://docs.nuget.org/docs/reference/versioning and the Semantic Versioning spec: http://semver.org/
    # 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
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

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

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

You must be logged in to reply to this topic.