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")
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
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")