1

My goal is to deploy and run my python script from GitHub to my virtual machine via Azure Pipeline. My azure-pipelines.yml looks like this:

jobs: - deployment: VMDeploy displayName: Test_script environment: name: deploymentenvironment resourceType: VirtualMachine strategy: rolling: maxParallel: 2 #for percentages, mention as x% preDeploy: steps: - download: current - script: echo initialize, cleanup, backup, install certs deploy: steps: - task: Bash@3 inputs: targetType: 'inline' script: python3 $(Agent.BuildDirectory)/test_file.py routeTraffic: steps: - script: echo routing traffic postRouteTraffic: steps: - script: echo health check post-route traffic on: failure: steps: - script: echo Restore from backup! This is on failure success: steps: - script: echo Notify! This is on success 

This returns an error:

/usr/bin/python3: can't find '__main__' module in '/home/ubuntu/azagent/_work/1/test_file.py' ##[error]Bash exited with code '1'. 

If I place the test_file.py to the /home/ubuntu and replace the deployment script with the following: script: python3 /home/ubuntu/test_file.py the script does run smoothly.

If I move the test_file.py to another directory with mv /home/ubuntu/azagent/_work/1/test_file.py /home/ubuntu I can find an empty folder, not a .py file, named of test_file.py

EDIT

Screenshot from Jobs:

enter image description here

6
  • How's the structure of your Python project? If you run your project locally via command line, how's the result? Could you set variable system.debug to true and share the entire log. Commented Aug 12, 2020 at 3:51
  • Python project in GitHub contains only azure-pipelines.yml and test_file.py. When I run the test_file.py in command line, it works (prints a sentence at this point. I'm going to add the real script to GitHub later). Please find the logs here: link. For some reason, now the error is about not finding the test_file.py. Commented Aug 12, 2020 at 12:10
  • You may try using $(Build.SourcesDirectory) in your script to see how's the result. If you still get failed build, please login to the agent machine, navigate to the location $(Build.SourcesDirectory), and run the script from command line locally to see how the result. Commented Aug 13, 2020 at 3:17
  • For some reason, that $(Build.SourcesDirectory) (/home/ubuntu/azagent/_work/2/s/) is empty. And I looked other directories under the _work folder and they seemed empty as well. I think, that those files are not even uploaded to my virtual machine. Do you know, what might be the reason? Commented Aug 13, 2020 at 6:56
  • Please check CheckOut log to see whether the project is checked out successfully. Could you share your entire log? Commented Aug 13, 2020 at 8:16

1 Answer 1

1

The reason that you can not get the source is because you use download: current to download artifacts produced by the current pipeline run, but you didn't publish any artifact in current pipeline.

As deployment jobs doesn't automatically check out source code, you need either checkout the source in your deployment job,

 - checkout: self 

or publish the sources to the artifact before downloading it.

 - publish: $(Build.SourcesDirectory) artifact: Artifact_Deploy 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.