Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.

If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!

Using curl to either check or download a script file in Otter



  • Hi,

    I am trying to conditionally run Get-Asset in an Otter script based on the existence of a script in the default raft. I am using curl and regardless if the script is there or not, I always get a positive return. Example (foo.config does not exist):

    curl.exe --head "https://<server_url>/0x44/Otter.WebApplication/Inedo.Otter.WebApplication.Pages.Scripts.ListScriptsPage/DownloadAsset?id=Default::BinaryFile::<path_to_script>/foo.config"
    HTTP/1.1 302 Found

    How can I either conditionally run Get-Asset or use curl to check for a script in the raft?

    Thanks,
    Scott


  • inedo-engineer

    Hi @scusson_9923 ,

    That is an internal/web-only API url, so it wouldn't behave quite right outside a web browser.

    I can't think of an easy way to accomplish what you're looking to do.... if you could share some of the bigger picture, maybe we can come up with a different approach / idea that would be easier to accomplish.

    Thanks,
    Alana



  • Hello Alana,

    We want to add to our current functionality and make it backward compatible. We have an archive job running in Jenkins which then uploads a config file to Otter and triggers a job. That Otter job runs remotely using Otter\PowerShell scripts with that config file and an input. What we want to do is have a related archive job with its own config file use the same Otter\PowerShell scripts. The issue is, we cannot guarantee that both config files will exist. It would help greatly if we can conditionally get an asset.

    Thanks,
    Scott


  • inedo-engineer

    Hi @scusson_9923 ,

    One idea ... how about a try/catch block?

    It's not great.... but the catch will indicate the file doesn't exist.

    Just a thought...

    Thanks,
    Alana



  • Hello Alana,

    I tried that, but the catch returns as error if the file doesn't exist and fails the job.

    Thanks,
    Scott


  • inedo-engineer

    Hi @scusson_9923 ,

    Can you share the OtterScript where you tried the try/catch ? Perhasp that's just something we can more easily fix.

    -- Dean



  • Hello Dean,

    Here is a test script:

    try
    {
        Get-Asset FooBar.ps1
        (
            Overwrite: true,
            Type: Script,
            To: D:\temp\FooBar.ps1
        );
    }
    catch
    {
        Log-Information did we catch?;
    }
    

    Here is the Otter output:

    DEBUG: Beginning execution run...
    INFO: Execution run succeeded.
    DEBUG: Beginning execution run...
    INFO: Execution run succeeded.
    DEBUG: Beginning execution run...
    INFO: Execution run succeeded.
    DEBUG: Beginning execution run...
    INFO: Execution run succeeded.
    DEBUG: Job will be run against servers sequentially (not asynchronously).
    DEBUG: Targeting servers: Otter host <host>
    INFO: did we catch?
    INFO: did we catch?
    ERROR: The raft Default does not contain an asset of type Script with the name FooBar.ps1.
    DEBUG: Cleaning up temporary files on Local Server...
    

    Thanks,
    Scott


  • inedo-engineer

    Hi @scusson_9923 ,

    Sorry on the slow reply; i wanted to test this, but didn't get a chance and figure I'd just share this now (which should work):

    set $scriptExists = true;
    
    try
    {
        Get-Asset FooBar.ps1
        (
            Overwrite: true,
            Type: Script,
            To: D:\temp\FooBar.ps1
        );
    }
    catch
    {
        set $scriptExists = false;
        force normal;
    }
    
    Log-Information scriptExists: $scriptExists;
    

    Cheers,
    Steve


Log in to reply
 

Inedo Website HomeSupport HomeCode of ConductForums GuideDocumentation