# Copyright (c) Microsoft Corporation.# Licensed under the MIT License."""Example of leveraging default authentication flowsRefer to the authentication section in the README for details:https://github.com/microsoft/fabric-cicd/tree/main?tab=readme-ov-file#authentication"""fromfabric_cicdimportFabricWorkspace,publish_all_items,unpublish_all_orphan_items# Sample values for FabricWorkspace parametersworkspace_id="your-workspace-id"environment="your-environment"repository_directory="your-repository-directory"item_type_in_scope=["Notebook","DataPipeline","Environment"]# Initialize the FabricWorkspace object with the required parameterstarget_workspace=FabricWorkspace(workspace_id=workspace_id,environment=environment,repository_directory=repository_directory,item_type_in_scope=item_type_in_scope,)# Publish all items defined in item_type_in_scopepublish_all_items(target_workspace)# Unpublish all items defined in item_type_in_scope not found in repositoryunpublish_all_orphan_items(target_workspace)
# Copyright (c) Microsoft Corporation.# Licensed under the MIT License."""Example of authenticating with SPN + SecretCan be expanded to retrieve values from Key Vault or other sources"""fromazure.identityimportClientSecretCredentialfromfabric_cicdimportFabricWorkspace,publish_all_items,unpublish_all_orphan_itemsclient_id="your-client-id"client_secret="your-client-secret"tenant_id="your-tenant-id"token_credential=ClientSecretCredential(client_id=client_id,client_secret=client_secret,tenant_id=tenant_id)# Sample values for FabricWorkspace parametersworkspace_id="your-workspace-id"environment="your-environment"repository_directory="your-repository-directory"item_type_in_scope=["Notebook","DataPipeline","Environment"]# Initialize the FabricWorkspace object with the required parameterstarget_workspace=FabricWorkspace(workspace_id=workspace_id,environment=environment,repository_directory=repository_directory,item_type_in_scope=item_type_in_scope,token_credential=token_credential,)# Publish all items defined in item_type_in_scopepublish_all_items(target_workspace)# Unpublish all items defined in item_type_in_scope not found in repositoryunpublish_all_orphan_items(target_workspace)
# Copyright (c) Microsoft Corporation.# Licensed under the MIT License."""Example to set variables based on the target environment.Environment is determined based on the branch that produced the build."""importosfrompathlibimportPathfromfabric_cicdimportFabricWorkspace,publish_all_items,unpublish_all_orphan_itemsbranch=os.getenv("BUILD_SOURCEBRANCHNAME")# The defined environment values should match the names found in the parameter.yml fileifbranch=="ppe":workspace_id="a2745610-0253-4cf3-9e47-0b5cf8aa00f0"environment="PPE"elifbranch=="main":workspace_id="9010397b-7c0f-4d93-8620-90e51816e9e9"environment="PROD"else:raiseValueError("Invalid branch to deploy from")# Sample values for FabricWorkspace parametersrepository_directory="your-repository-directory"item_type_in_scope=["Notebook","DataPipeline","Environment"]# Initialize the FabricWorkspace object with the required parameterstarget_workspace=FabricWorkspace(workspace_id=workspace_id,environment=environment,repository_directory=repository_directory,item_type_in_scope=item_type_in_scope,)# Publish all items defined in item_type_in_scopepublish_all_items(target_workspace)# Unpublish all items defined in item_type_in_scope not found in repositoryunpublish_all_orphan_items(target_workspace)
# Copyright (c) Microsoft Corporation.# Licensed under the MIT License."""Example to set variables based on the target environment.Environment is determined based on the current branch name."""frompathlibimportPathimportgit# Depends on pip install gitpythonfromfabric_cicdimportFabricWorkspace,publish_all_items,unpublish_all_orphan_items# In this example, this file is being ran in the root/sample directoryroot_directory=Path(__file__).resolve().parent.parentrepo=git.Repo(root_directory)repo.remotes.origin.pull()branch=repo.active_branch.name# The defined environment values should match the names found in the parameter.yml fileifbranch=="ppe":workspace_id="a2745610-0253-4cf3-9e47-0b5cf8aa00f0"environment="PPE"elifbranch=="main":workspace_id="9010397b-7c0f-4d93-8620-90e51816e9e9"environment="PROD"else:raiseValueError("Invalid branch to deploy from")# Sample values for FabricWorkspace parametersrepository_directory="your-repository-directory"item_type_in_scope=["Notebook","DataPipeline","Environment"]# Initialize the FabricWorkspace object with the required parameterstarget_workspace=FabricWorkspace(workspace_id=workspace_id,environment=environment,repository_directory=repository_directory,item_type_in_scope=item_type_in_scope,)# Publish all items defined in item_type_in_scopepublish_all_items(target_workspace)# Unpublish all items defined in item_type_in_scope not found in repositoryunpublish_all_orphan_items(target_workspace)
# Copyright (c) Microsoft Corporation.# Licensed under the MIT License."""Example of optional parameters for FabricWorkspace and publish functions."""fromfabric_cicdimportFabricWorkspace,change_log_level,publish_all_items,unpublish_all_orphan_items# Sample values for FabricWorkspace parametersworkspace_id="your-workspace-id"environment="your-environment"repository_directory="your-repository-directory"item_type_in_scope=["Notebook","DataPipeline","Environment"]base_api_url="https://msitapi.fabric.microsoft.com/"token_credential=TokenCredential# Optional: Print all API calls to log filechange_log_level("DEBUG")# Initialize the FabricWorkspace object with the required and optional parameterstarget_workspace=FabricWorkspace(workspace_id=workspace_id,environment=environment,repository_directory=repository_directory,item_type_in_scope=item_type_in_scope,# Optional: Override base URL in rare cases where it's differentbase_api_url=base_api_url,# Optional: Override token credential to use a different authenticationtoken_credential=token_credential,)# Publish all items defined in item_type_in_scopepublish_all_items(target_workspace)# Unpublish all items defined in item_type_in_scope not found in repositoryunpublish_all_orphan_items(target_workspace,# Optional: Exclude item names matching the regex patternitem_name_exclude_regex=r"^DEBUG.*",)