diff --git a/tools/ci_build/github/azure-pipelines/orttraining-py-packaging-pipeline-cpu.yml b/tools/ci_build/github/azure-pipelines/orttraining-py-packaging-pipeline-cpu.yml index b34d9f791d..8644f4b322 100644 --- a/tools/ci_build/github/azure-pipelines/orttraining-py-packaging-pipeline-cpu.yml +++ b/tools/ci_build/github/azure-pipelines/orttraining-py-packaging-pipeline-cpu.yml @@ -1,5 +1,14 @@ trigger: none +variables: + - name: isMain + value: ${{ eq(variables['Build.SourceBranch'], 'refs/heads/master') }} + - name: finalStorage + ${{ if eq(variables['isMain'], 'true') }}: + value: '--final_storage' + ${{ else }}: + value: '' + stages: - stage: Python_Packaging @@ -23,6 +32,14 @@ stages: PythonVersion: '3.9' steps: + - task: CmdLine@2 + displayName: 'check variables' + inputs: + script: | + echo "Branch is "${{ variables['Build.SourceBranch'] }} && \ + echo "isMain is "${{ variables['isMain'] }} && \ + echo "final_storage is "${{ variables['finalStorage'] }} + - checkout: self clean: true submodules: recursive @@ -78,14 +95,15 @@ stages: ArtifactName: onnxruntime_training_cpu - task: CmdLine@2 - condition: and (succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) + condition: succeeded() displayName: 'Upload wheel' inputs: script: | files=($(Build.ArtifactStagingDirectory)/Release/dist/*.whl) && \ echo ${files[0]} && \ + echo ${{ variables['finalStorage'] }} && \ tools/ci_build/upload_python_package_to_azure_storage.py \ - --python_wheel_path ${files[0]} + --python_wheel_path ${files[0]} ${{ variables['finalStorage'] }} - template: templates/component-governance-component-detection-steps.yml parameters: diff --git a/tools/ci_build/github/azure-pipelines/templates/py-packaging-training-cuda-stage.yml b/tools/ci_build/github/azure-pipelines/templates/py-packaging-training-cuda-stage.yml index 85dd578255..62c669638b 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-packaging-training-cuda-stage.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-packaging-training-cuda-stage.yml @@ -49,6 +49,15 @@ parameters: stages: - stage: Python_Packaging + variables: + - name: isMain + value: ${{ eq(variables['Build.SourceBranch'], 'refs/heads/master') }} + - name: finalStorage + ${{ if eq(variables['isMain'], 'true') }}: + value: '--final_storage' + ${{ else }}: + value: '' + jobs: - job: Linux_py_Training_Cuda_Wheels timeoutInMinutes: 180 @@ -83,6 +92,14 @@ stages: UploadWheel: ${{ parameters.upload_wheel }} steps: + - task: CmdLine@2 + displayName: 'check variables' + inputs: + script: | + echo "Branch is "${{ variables['Build.SourceBranch'] }} && \ + echo "isMain is "${{ variables['isMain'] }} && \ + echo "final_storage is "${{ variables['finalStorage'] }} + - checkout: self clean: true submodules: recursive @@ -215,7 +232,7 @@ stages: files=($(Build.ArtifactStagingDirectory)/Release/dist/*.whl) && \ echo ${files[0]} && \ python3 tools/ci_build/upload_python_package_to_azure_storage.py \ - --python_wheel_path ${files[0]} + --python_wheel_path ${files[0]} ${{ variables['finalStorage'] }} - template: component-governance-component-detection-steps.yml parameters: diff --git a/tools/ci_build/upload_python_package_to_azure_storage.py b/tools/ci_build/upload_python_package_to_azure_storage.py index a0b3ad5836..c30a1d8330 100755 --- a/tools/ci_build/upload_python_package_to_azure_storage.py +++ b/tools/ci_build/upload_python_package_to_azure_storage.py @@ -25,13 +25,14 @@ def parse_nightly_and_local_version_from_whl_name(blob_name): def run_subprocess(args, cwd=None): - log.debug("Running subprocess in '{0}'\n{1}".format(cwd or os.getcwd(), args)) + log.warning("Running subprocess in '{0}'\n{1}".format(cwd or os.getcwd(), args)) return subprocess.run(args, cwd=cwd, check=True) -def upload_whl(python_wheel_path): +def upload_whl(python_wheel_path, final_storage=False): + storage_account_name = "onnxruntimepackages" if final_storage else "onnxruntimepackagesint" blob_name = os.path.basename(python_wheel_path) - run_subprocess(['azcopy', 'cp', python_wheel_path, 'https://onnxruntimepackages.blob.core.windows.net/$web/']) + run_subprocess(['azcopy', 'cp', python_wheel_path, f'https://{storage_account_name}.blob.core.windows.net/$web/']) nightly_build, local_version = parse_nightly_and_local_version_from_whl_name(blob_name) if local_version: @@ -41,7 +42,7 @@ def upload_whl(python_wheel_path): download_path_to_html = "./onnxruntime_{}.html".format(nightly_build) - run_subprocess(['azcopy', 'cp', 'https://onnxruntimepackages.blob.core.windows.net/$web/'+html_blob_name, + run_subprocess(['azcopy', 'cp', f'https://{storage_account_name}.blob.core.windows.net/$web/'+html_blob_name, download_path_to_html]) blob_name_plus_replaced = blob_name.replace('+', '%2B') @@ -59,7 +60,7 @@ def upload_whl(python_wheel_path): else: warnings.warn("'{}' exists in {}. The html file is not updated.".format(new_line, download_path_to_html)) run_subprocess(['azcopy', 'cp', download_path_to_html, - 'https://onnxruntimepackages.blob.core.windows.net/$web/'+html_blob_name, + f'https://{storage_account_name}.blob.core.windows.net/$web/'+html_blob_name, '--content-type', 'text/html', '--overwrite', 'true']) @@ -67,7 +68,8 @@ if __name__ == "__main__": parser = argparse.ArgumentParser(description="Upload python whl to azure storage.") parser.add_argument("--python_wheel_path", type=str, help="path to python wheel") + parser.add_argument("--final_storage", action='store_true', help="upload to final storage") args = parser.parse_args() - upload_whl(args.python_wheel_path) + upload_whl(args.python_wheel_path, args.final_storage)