terça-feira, 5 de julho de 2022

Implantando Pacotes automaticamente em SandBox - D365 F&O

 Na postagem anterior, expliquei como é feito o build e empacotamento através de um Pipeline no Azure. Mas dai vem a dúvida. - Eu vou ter que subir aquele pacote gerado pelo pipeline manualmente pelo LCS, me minha SandBox? A resposta é: Não!

Você precisará criar um Release no Azure DevOps. Para isso, importe o seguinte json em seu projeto no Azure DevOps:

{"source":2,"revision":34,"description":null,"createdBy":{"displayName":"Otavio Anaga","url":"https://spsprodsbr1.vssps.visualstudio.com/A56f87ddd-07a4-409d-8f49-f17f22b12cbb/_apis/Identities/774c7aa6-f081-6c47-beb5-22138886fbe7","_links":{"avatar":{"href":"https://dev.azure.com/ContosoD365/_apis/GraphProfile/MemberAvatars/aad.Nzc0YzdhYTYtZjA4MS03YzQ3LWJlYjUtMjIxMzg4ODZmYmU3"}},"id":"774c7aa6-f081-6c47-beb5-22138886fbe7","uniqueName":"otavioanaga@Contoso.com.br","imageUrl":"https://dev.azure.com/ContosoD365/_apis/GraphProfile/MemberAvatars/aad.Nzc0YzdhYTYtZjA4MS03YzQ3LWJlYjUtMjIxMzg4ODZmYmU3","descriptor":"aad.Nzc0YzdhYTYtZjA4MS03YzQ3LWJlYjUtMjIxMzg4ODZmYmU3"},"createdOn":"2021-10-23T18:02:00.000Z","modifiedBy":{"displayName":"Otavio Anaga Anaga","url":"https://spsprodsbr1.vssps.visualstudio.com/A56f87ddd-07a4-409d-8f49-f17f22b12cbb/_apis/Identities/774c7aa6-f081-6c47-beb5-22138886fbe7","_links":{"avatar":{"href":"https://dev.azure.com/ContosoD365/_apis/GraphProfile/MemberAvatars/aad.Nzc0YzdhYTYtZjA4MS03YzQ3LWJlYjUtMjIxMzg4ODZmYmU3"}},"id":"774c7aa6-f081-6c47-beb5-22138886fbe7","uniqueName":"otavioanaga@Contoso.com.br","imageUrl":"https://dev.azure.com/ContosoD365/_apis/GraphProfile/MemberAvatars/aad.Nzc0YzdhYTYtZjA4MS03YzQ3LWJlYjUtMjIxMzg4ODZmYmU3","descriptor":"aad.Nzc0YzdhYTYtZjA4MS03YzQ3LWJlYjUtMjIxMzg4ODZmYmU3"},"modifiedOn":"2022-07-05T20:58:06.397Z","isDeleted":false,"lastRelease":{"id":211,"name":"Release-211","artifacts":[],"_links":{},"description":"Triggered by Release to SandBox 22.07.05.1.","releaseDefinition":{"id":1,"projectReference":null,"_links":{}},"createdOn":"2022-07-05T08:43:57.910Z","createdBy":{"displayName":"Microsoft.VisualStudio.Services.TFS","url":"https://spsprodsbr1.vssps.visualstudio.com/A56f87ddd-07a4-409d-8f49-f17f22b12cbb/_apis/Identities/00000002-0000-8888-8000-000000000000","_links":{"avatar":{"href":"https://dev.azure.com/ContosoD365/_apis/GraphProfile/MemberAvatars/s2s.MDAwMDAwMDItMDAwMC04ODg4LTgwMDAtMDAwMDAwMDAwMDAwQDJjODk1OTA4LTA0ZTAtNDk1Mi04OWZkLTU0YjAwNDZkNjI4OA"}},"id":"00000002-0000-8888-8000-000000000000","uniqueName":"00000002-0000-8888-8000-000000000000@2c895908-04e0-4952-89fd-54b0046d6288","imageUrl":"https://dev.azure.com/ContosoD365/_apis/GraphProfile/MemberAvatars/s2s.MDAwMDAwMDItMDAwMC04ODg4LTgwMDAtMDAwMDAwMDAwMDAwQDJjODk1OTA4LTA0ZTAtNDk1Mi04OWZkLTU0YjAwNDZkNjI4OA","descriptor":"s2s.MDAwMDAwMDItMDAwMC04ODg4LTgwMDAtMDAwMDAwMDAwMDAwQDJjODk1OTA4LTA0ZTAtNDk1Mi04OWZkLTU0YjAwNDZkNjI4OA"}},"variables":{"Client":{"value":"Contoso"},"LCSEnvironmentId":{"value":"5780497e-254b-4b6e-8219-850d646e9918"},"LCsProjectId":{"value":"1533614"}},"variableGroups":[],"environments":[{"id":1,"name":"Build to LCS","rank":1,"owner":{"displayName":"Otavio Anaga","url":"https://spsprodsbr1.vssps.visualstudio.com/A56f87ddd-07a4-409d-8f49-f17f22b12cbb/_apis/Identities/774c7aa6-f081-6c47-beb5-22138886fbe7","_links":{"avatar":{"href":"https://dev.azure.com/ContosoD365/_apis/GraphProfile/MemberAvatars/aad.Nzc0YzdhYTYtZjA4MS03YzQ3LWJlYjUtMjIxMzg4ODZmYmU3"}},"id":"774c7aa6-f081-6c47-beb5-22138886fbe7","uniqueName":"otavioanaga@Contoso.com.br","imageUrl":"https://dev.azure.com/ContosoD365/_apis/GraphProfile/MemberAvatars/aad.Nzc0YzdhYTYtZjA4MS03YzQ3LWJlYjUtMjIxMzg4ODZmYmU3","descriptor":"aad.Nzc0YzdhYTYtZjA4MS03YzQ3LWJlYjUtMjIxMzg4ODZmYmU3"},"variables":{},"variableGroups":[],"preDeployApprovals":{"approvals":[{"rank":1,"isAutomated":true,"isNotificationOn":false,"id":1}],"approvalOptions":{"requiredApproverCount":null,"releaseCreatorCanBeApprover":false,"autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped":false,"enforceIdentityRevalidation":false,"timeoutInMinutes":0,"executionOrder":1}},"deployStep":{"id":2},"postDeployApprovals":{"approvals":[{"rank":1,"isAutomated":true,"isNotificationOn":false,"id":3}],"approvalOptions":{"requiredApproverCount":null,"releaseCreatorCanBeApprover":false,"autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped":false,"enforceIdentityRevalidation":false,"timeoutInMinutes":0,"executionOrder":2}},"deployPhases":[{"deploymentInput":{"parallelExecution":{"parallelExecutionType":0},"agentSpecification":{"identifier":"windows-latest"},"skipArtifactsDownload":false,"artifactsDownloadInput":{"downloadInputs":[]},"queueId":27,"demands":[],"enableAccessToken":false,"timeoutInMinutes":0,"jobCancelTimeoutInMinutes":1,"condition":"succeeded()","overrideInputs":{}},"rank":1,"phaseType":1,"name":"Agent job","refName":null,"workflowTasks":[{"environment":{},"taskId":"31f040e5-e040-4336-878a-59a493355534","version":"1.*","name":"Initialize variable","refName":"","enabled":true,"alwaysRun":false,"continueOnError":false,"timeoutInMinutes":0,"retryCountOnTaskFailure":0,"definitionType":"task","overrideInputs":{},"condition":"succeeded()","inputs":{"Script":"#This simply exposes the Client parameter, required because of the way Task Groups expose variables to users of the group\n$tmp = \"$(Client)\"","ScriptArguments":""}},{"environment":{},"taskId":"78a30d98-c4a6-5ef0-b077-f3ef46c771d6","version":"0.*","name":"Upload $(Release.ReleaseName) - $(Build.BuildNumber) to project $(LcsProjectId)","refName":"","enabled":true,"alwaysRun":false,"continueOnError":false,"timeoutInMinutes":0,"retryCountOnTaskFailure":0,"definitionType":"task","overrideInputs":{},"condition":"succeeded()","inputs":{"serviceConnectionName":"efa96d8d-f51e-4081-a466-469ba3456f5f","projectId":"$(LcsProjectId)","assetType":"10","assetPath":"$(System.DefaultWorkingDirectory)/_Release to SandBox/drop/AXDeployableRuntime_$(Build.BuildNumber).zip","assetName":"$(Release.ReleaseName) - $(Build.BuildNumber)","assetDescription":"$(Release.ReleaseName) - $(Build.BuildNumber)","waitForValidation":"true"}},{"environment":{},"taskId":"31f040e5-e040-4336-878a-59a493355534","version":"1.*","name":"Get asset ID","refName":"","enabled":true,"alwaysRun":false,"continueOnError":false,"timeoutInMinutes":0,"retryCountOnTaskFailure":0,"definitionType":"task","overrideInputs":{},"condition":"succeeded()","inputs":{"Script":"$assetId= $env:LCSASSETUPLOAD_FILEASSETID\nWrite-Host(\"##vso[task.setvariable variable=AssetId;]$assetId\")","ScriptArguments":""}},{"environment":{},"taskId":"31f040e5-e040-4336-878a-59a493355534","version":"1.*","name":"Inline Powershell","refName":"","enabled":true,"alwaysRun":false,"continueOnError":false,"timeoutInMinutes":0,"retryCountOnTaskFailure":0,"definitionType":"task","overrideInputs":{},"condition":"succeeded()","inputs":{"Script":"Install-Module -Name 'MSAL.PS' -RequiredVersion '4.21.0.1' -AcceptLicense -Force","ScriptArguments":""}},{"environment":{},"taskId":"5852aa2c-30d2-517f-b766-bd37640e8a06","version":"2.*","name":"Deploy to sandbox2","refName":"","enabled":true,"alwaysRun":false,"continueOnError":false,"timeoutInMinutes":0,"retryCountOnTaskFailure":0,"definitionType":"task","overrideInputs":{},"condition":"succeeded()","inputs":{"serviceConnectionName":"efa96d8d-f51e-4081-a466-469ba3456f5f","projectId":"$(LcsProjectId)","environmentId":"$(LCSEnvironmentId)","fileAssetId":"$(assetId)","releaseName":"$(Release.ReleaseName) - $(Build.BuildNumber)","waitForCompletion":"false"}}]}],"environmentOptions":{"emailNotificationType":"OnlyOnFailure","emailRecipients":"release.environment.owner;release.creator","skipArtifactsDownload":false,"timeoutInMinutes":0,"enableAccessToken":false,"publishDeploymentStatus":true,"badgeEnabled":false,"autoLinkWorkItems":false,"pullRequestDeploymentEnabled":false},"demands":[],"conditions":[{"name":"ReleaseStarted","conditionType":1,"value":""}],"executionPolicy":{"concurrencyCount":1,"queueDepthCount":0},"schedules":[],"currentRelease":{"id":211,"url":"https://vsrm.dev.azure.com/ContosoD365/86984b62-8527-44d3-a2bc-d4c80f907df1/_apis/Release/releases/211","_links":{}},"retentionPolicy":{"daysToKeep":30,"releasesToKeep":3,"retainBuild":true},"processParameters":{},"properties":{"BoardsEnvironmentType":{"$type":"System.String","$value":"unmapped"},"LinkBoardsWorkItems":{"$type":"System.String","$value":"False"}},"preDeploymentGates":{"id":0,"gatesOptions":null,"gates":[]},"postDeploymentGates":{"id":0,"gatesOptions":null,"gates":[]},"environmentTriggers":[],"badgeUrl":"https://vsrm.dev.azure.com/ContosoD365/_apis/public/Release/badge/86984b62-8527-44d3-a2bc-d4c80f907df1/1/1"}],"artifacts":[{"sourceId":"86984b62-8527-44d3-a2bc-d4c80f907df1:3","type":"Build","alias":"_Release to SandBox","definitionReference":{"artifactSourceDefinitionUrl":{"id":"https://dev.azure.com/ContosoD365/_permalink/_build/index?collectionId=8b14f745-7fe1-47eb-ac2d-527e8b5f453f&projectId=86984b62-8527-44d3-a2bc-d4c80f907df1&definitionId=3","name":""},"defaultVersionBranch":{"id":"","name":""},"defaultVersionSpecific":{"id":"","name":""},"defaultVersionTags":{"id":"","name":""},"defaultVersionType":{"id":"latestType","name":"Latest"},"definition":{"id":"3","name":"Midnight Schedule - MS Hosted Agent Pipeline-import"},"definitions":{"id":"","name":""},"IsMultiDefinitionType":{"id":"False","name":"False"},"project":{"id":"86984b62-8527-44d3-a2bc-d4c80f907df1","name":"Dynamics 365"},"repository":{"id":"","name":""}},"isPrimary":true,"isRetained":false}],"triggers":[{"artifactAlias":"_Release to SandBox","triggerConditions":[],"triggerType":1}],"releaseNameFormat":"Release-$(rev:r)","tags":[],"properties":{"DefinitionCreationSource":{"$type":"System.String","$value":"ReleaseNew"},"IntegrateBoardsWorkItems":{"$type":"System.String","$value":"False"},"IntegrateJiraWorkItems":{"$type":"System.String","$value":"false"}},"id":1,"name":"Apply Package on SandBox","path":"\\","projectReference":null,"url":"https://vsrm.dev.azure.com/ContosoD365/86984b62-8527-44d3-a2bc-d4c80f907df1/_apis/Release/definitions/1","_links":{"self":{"href":"https://vsrm.dev.azure.com/ContosoD365/86984b62-8527-44d3-a2bc-d4c80f907df1/_apis/Release/definitions/1"},"web":{"href":"https://dev.azure.com/ContosoD365/86984b62-8527-44d3-a2bc-d4c80f907df1/_release?definitionId=1"}}}

Importe através do botão representado na imagem abaixo:


Na aba de variáveis, serão 3:




Client - é o tenant da empresa. Por exemplo, otavioanaga@contoso.com.br o tenant seria contoso

LCSEnvironmentId - é a guid do ambiente que receberá a release. Ela está disponível no LCS, na aba Manage Enviroment campo Enviroment Id

LCSProjectId - Acesse o projeto via LCS. O id do projeto é o número no final da URL.

Volte para a aba pipeline e configure o Artifacts:

É no Artifacts que referenciamos aquele pacote gerado pelo nosso pipeline. Delete o Artifact que veio com o arquivo e crie novamente através do botão Add, a configuração deve ser parecida com a imagem abaixo:



Importante: Certifique-se de que o Source Alias exibido nesta tela esteja contido na propriedade File to Upload do passo de upload contido na aba Tasks.





Uma vez configurado o Artifact, selecione o  e verifique o status da opção abaixo. Se ela estiver habilitada, então TODO build do pipeline configurado no passo anterior que ocorrer com sucesso, chamará o seu Release, então vai de você julgar se isso cabe no seu planejamento ou não:




Com tudo devidamente parametrizado, para testar basta ir até à pagina de releases no Azure Devops e selecionar Create a Release






Lembrando que só é possível implantar pacotes automaticamente em ambiente Sandbox. Em ambiente produtivo isso ainda não é possível. 

Quaisquer dúvidas é só postar na área de comentários.

Nenhum comentário:

Postar um comentário