Search code examples
azureteams-toolkit

Login via CLI for CI/CD


I can deploy my team app via the visual studio code extension, but I'm trying to set up a Continuous Deployment. I'm following this doc (since I'm not using Github but azure Devops): https://github.com/OfficeDev/TeamsFx/blob/dev/docs/cicd/others-script-cd-template.sh

My script (that I execute on a remote machine looks like):

#!/usr/bin/env bash
set -euxo pipefail

AZURE_ACCOUNT_NAME="xxxxx@xx.xx"
AZURE_ACCOUNT_PASSWORD="yyyyyyy"
AZURE_SUBSCRIPTION_ID="zzzzzz"
AZURE_TENANT_ID="aaaaaa"
M365_ACCOUNT_NAME="xxxxx@xx.xx"
M365_ACCOUNT_PASSWORD="yyyyyyy"


#npx teamsfx deploy
npx teamsfx account login azure

For each try I do (with different commands) the result is:

[TeamsfxCLI] Log in to your Azure account - opening default web browser at https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize?client_id=7ea7c24c-b1f6-4a20-9d11-9ae12e9e7ac0&scope=https%3A%2F%2Fmanagement.core.windows.net%2Fuser_impersonation%20openid%20profile%20offline_access&redirect_uri=http%3A%2F%2Flocalhost%3A45315&client-request-id=c4a5a5a6-45d5-40da-a5a9-8acedac8df52&response_mode=query&response_type=code&x-client-SKU=msal.js.node&x-client-VER=1.0.0-beta.6&x-client-OS=linux&x-client-CPU=x64&client_info=1&code_challenge=MdFhzm7OTWFzSYgxwsgj6A4X9A5cricL-N03nY-qTUo&code_challenge_method=S256&prompt=select_account
Error: spawn xdg-open ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    at onErrorNT (internal/child_process.js:467:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn xdg-open',
  path: 'xdg-open',
  spawnargs: [
    'https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize?client_id=7ea7c24c-b1f6-4a20-9d11-9ae12e9e7ac0&scope=https%3A%2F%2Fmanagement.core.windows.net%2Fuser_impersonation%20openid%20profile%20offline_access&redirect_uri=http%3A%2F%2Flocalhost%3A45315&client-request-id=c4a5a5a6-45d5-40da-a5a9-8acedac8df52&response_mode=query&response_type=code&x-client-SKU=msal.js.node&x-client-VER=1.0.0-beta.6&x-client-OS=linux&x-client-CPU=x64&client_info=1&code_challenge=MdFhzm7OTWFzSYgxwsgj6A4X9A5cricL-N03nY-qTUo&code_challenge_method=S256&prompt=select_account'
  ]
}

I've no other info, I don't know if my credentials are incorrect, or if I missed something else.

Do I use the correct method to deploy my app on a remote machine ?


Solution

    1. one extra environment variable is missing in the script. Please add one more environment for the cli like below:

    export CI_ENABLED=true.

    To give more details, CI_ENABLED=true will make cli work in CI mode which will not have the interactive parts like login by opening a browser as the error told you.

    1. please use export to export environment variables like below:
    export AZURE_ACCOUNT_NAME=xxx
    export AZURE_ACCOUNT_PASSWORD=xxx
    ...
    

    The normal variable assignment as shown in your script will not work for CLI.

    The doc is already updated accordingly, also, please kindly let me know if your issue get solved finally, thanks.

    BTW, CICD Support for Azure DevOps is on the way.