Stop execution of dependent resources if Script doesn't satisfy

Tagged: 

This topic contains 2 replies, has 3 voices, and was last updated by Profile photo of Arie H Arie H 2 months, 4 weeks ago.

  • Author
    Posts
  • #53983
    Profile photo of Sameer Kumar
    Sameer Kumar
    Participant

    I'm using TFS 2015 U2 RM to execute DSC configurations on target nodes. This particular configuration would deploy website and has many resources in it. I want to add a Script as my first resource on which other resources would have DependsOn. And in this first Script resource, I want to check if a folder exists and IIS binding exists for the same, prevent other resources from execution. Let me try with an example.

    Node ($AllNodes.NodeName)
    {
            Script ScriptResource01
            {
                TestScript = {
                    $destinationPath = "E:\Programs\prd\DevCI_20160909.3"
                    if (Test-Path $using:destinationPath) {
                        Write-Verbose -Message "Website already deployed." -Verbose
                        return $true
                    }
                    return $false
                }
                SetScript = {
                    Write-Verbose -Message "Paths are valid." -Verbose
                }
                GetScript = { @{ Result = "Validate if website already edeployed." } }
            }
    
            Script ScriptResource02
            {
                DependsOn  = @("[Script]ScriptResource01")
                TestScript = {
                    return $false
                }
                SetScript = {
                    Write-Verbose -Message "Deploying website in this block" -Verbose
                }
                GetScript = { @{ Result = "Copies the website content to the right folder." } }
            }
    }

    In this example, I want to prevent execution of ScriptResource02 if ScriptResource01's SetScript didn't run.
    If I use Write-Error it stops the execution however TFS RM console also fails-out which is unwanted for us.

    Thanks for your help.

    • This topic was modified 2 months, 4 weeks ago by Profile photo of Sameer Kumar Sameer Kumar.
  • #53985
    Profile photo of Nitin Gupta
    Nitin Gupta
    Participant

    There is no easy way to do that in DSC today. There is a similar issue opened on uservoice (https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/11088639-enable-service-restart-and-similar-scenarios-in-ds) to handle this kind of scenario. I encourage you to upvote this uservoice item such that DSC team can prioritize and fix it soon.

  • #54004
    Profile photo of Arie H
    Arie H
    Participant

    Back in RM 2013 I did something similar on that level by running a PS script that went to a DB and looked for a value to be 1
    and then proceed with execution. This was the orchestration outside of DSC as the DependsOn and WaitFor are somewhat limited.

    With the changes to TFS2015 U2, it should be even easier to do the orchestration, just use 2 DSC scripts for that node
    one with the full script and one with just what's needed and do the logic outside. Even if you've used a pull server with ConfigurationNames you can have a step in RM that will rename the mof accordingly and do the checksum ofc.

You must be logged in to reply to this topic.