Passing values from notebook to 'Set Variable' transformation within pipeline.

Peter Ott 1 Reputation point
2024-09-26T16:00:37.1633333+00:00

I have a synapse notebook in which I return a json string using:

...

variables_dict = {
    "adlspath": adlspath,
    "MDPKeyVault": MDPKeyVault,
    "jdbcHostname": jdbcHostname,
    "jdbcDatabase": jdbcDatabase
}

"jdbcDatabase": jdbcDatabase}
result = json.dumps(variables_dict)
mssparkutils.notebook.exit(result)

The ExitValue is: 

I can see the json in the output of the notebook, and the input of my 'Set Variable'. I'd like to parse this json string within the calling pipeline using 'Set Variable' transformations.  1. Is this possible?  2. What would be the 'Value' of my variables?
Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,914 questions
{count} votes

1 answer

Sort by: Most helpful
  1. phemanth 10,335 Reputation points Microsoft Vendor
    2024-09-27T09:51:38.9866667+00:00

    @Peter Ott

    Thanks for reaching out to Microsoft Q&A

    It looks like you’re trying to pass values from a Synapse notebook to a ‘Set Variable’ transformation within a pipeline. You have the JSON string ready, but it seems like you’re stuck on the next steps.

    Here’s how you can proceed:

    1. Capture the JSON Output: Ensure that your notebook’s output is correctly captured by the pipeline activity. The mssparkutils.notebook.exit(result) should return the JSON string as the output.
    2. Set Variable Activity: In your pipeline, use the ‘Set Variable’ activity to parse and assign the values from the JSON string to pipeline variables.

    Here’s a step-by-step guide:

    Step 1: Notebook Activity

    Ensure your notebook activity is configured to capture the output. Your code seems correct for generating the JSON string.

    import json
    variables_dict = {
        "adlspath": adlspath,
        "MDPKeyVault": MDPKeyVault,
        "jdbcHostname": jdbcHostname,
        "jdbcDatabase": jdbcDatabase
    }
    result = json.dumps(variables_dict)
    mssparkutils.notebook.exit(result)
    
    

    Step 2: Set Variable Activity

    Add a ‘Set Variable’ activity to your pipeline.

    Link the ‘Set Variable’ activity to the notebook activity.

    Configure the ‘Set Variable’ activity:

    • Variable Name: Choose the variable you want to set.
    • Value: Use the following expression to extract the value from the notebook output:
    @json(activity('NotebookActivityName').output.runOutput).adlspath
    
    

    Example

    If your notebook activity is named RunNotebook, and you want to set the adlspath variable, the expression would be:

    @json(activity('NotebookActivityName').output.runOutput).adlspath
    
    

    Repeat this for each variable you need to set.

    Hope this helps. Do let us know if you any further queries.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.