mathworks / matlab-azure-devops-extension

Continuous Integration with MATLAB on Azure DevOps
https://marketplace.visualstudio.com/items?itemName=MathWorks.matlab-azure-devops-extension
Other
14 stars 5 forks source link

How to access output of Matlab function in other tasks? #100

Closed bavodenys closed 1 year ago

bavodenys commented 1 year ago

Hi

I have a Azure pipeline with a task to open a project in Matlab and to run a Matlab script (fcnBuildAll) to build my application. How can I access the output of the function fcnBuildAll() and use it in the task PublishArtifacts? I like to use BuildSuccess in the condition section of PublishBuildArtifacts to only publish if the build was successful. How should I modify this section of code to have the desired functionality? Thanks in advance!

mcafaro commented 1 year ago

Hi,

You can set variables in Azure Pipelines by printing a specially formatted string to the log (via the MATLAB disp command for example). See the Set variables in scripts documentation for more details.

Below is an example of setting a pipeline variable in MATLAB and using it in a subsequent task condition (ported from this Azure Pipelines documentation example):

  # This step creates a new pipeline variable: doThing. This variable will be available to subsequent steps.
  - task: RunMATLABCommand@0
    inputs:
      command: |
        myvalue = "Yes";
        disp("##vso[task.setvariable variable=doThing]" + myvalue);

  # This step is able to use doThing in its condition as well as its body
  - script: |
      # You can access the variable from Step 1 as an environment variable.
      echo "Value of doThing (as DOTHING env var): $DOTHING."
    condition: and(succeeded(), eq(variables['doThing'], 'Yes'))

Best, Mark

bavodenys commented 1 year ago

Hi

Thanks, it worked!!

Best regards