0

enter image description here

I am working on writing a function in python azure automation runbook, where the basic gist of what I'm trying to accomplish is shown in the code below. But, I'm perplexed as when I take the code out of the function and run the code as is it all works as expected. But, when the function is used I see the output for Start & End but I don't see the function getting executed. I'm not clear the piece I miss for this to not work.

Python:

import sys
import requests
print ("Start")

def myFunction():
    # do something
    print("This is my function doing something")

myFunction()   

print ("End")

1 Answer 1

1

Your code worked successfully and achieved the expected outcomes when I tried it in my environment, as shown below:

First and foremost, you should add the requests(3.8) module/package to the Azure Automation runbook as you are using it in code.

Add a package:

Path:

Azure automation account -> Python packages -> Add a Python Package

enter image description here

Note: Versions of Python runbook and packages should be compatible with each other.

I've created a Python runbook (3.8) and the function code was successfully executed.

#!/usr/bin/env python3
import sys
import requests
print ("Start")
def myFunction():
print("This is my function doing something")
myFunction()
print ("End")

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

I am using hybrid worker group to run it and all I see is Start & End. I'll update my post with the results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.