Azure / azure-dev

A developer CLI that reduces the time it takes for you to get started on Azure. The Azure Developer CLI (azd) provides a set of developer-friendly commands that map to key stages in your workflow - code, build, deploy, monitor, repeat.
https://aka.ms/azd
MIT License
392 stars 185 forks source link

[Feature] Support AzDo using SSH #1896

Closed ardeshir closed 3 weeks ago

ardeshir commented 1 year ago

Output from azd version azd version 0.7.0-beta.1 (commit 9ce71659f7688d0dc3dda8b84e5accedca58cf01)

Describe the bug Command: azd pipeline config --provider azdo

To Reproduce Command: azd pipeline config --provider azdo

Expected behavior Expected to have ado pipeline for template

Environment Information on your environment:

Additional context The repository is a Microsoft Demo [https://github.com/Azure-Samples/azure-search-openai-demo/ ]

panic: runtime error: index out of range [1] with length 1
goroutine 1 [running]:
[github.com/azure/azure-dev/cli/azd/pkg/commands/pipeline.(*AzdoScmProvider).gitRepoDetails(0xc00054a900](http://github.com/azure/azure-dev/cli/azd/pkg/commands/pipeline.(*AzdoScmProvider).gitRepoDetails(0xc00054a900), {0x100b7c0e8, 0xc00056e870}, {0xc0003b8040, 0x3d})
        /Users/runner/work/1/s/cli/azd/pkg/commands/pipeline/azdo_provider.go:480 +0xb85
[github.com/azure/azure-dev/cli/azd/pkg/commands/pipeline.(*PipelineManager).ensureRemote(0xc00013e0c0](http://github.com/azure/azure-dev/cli/azd/pkg/commands/pipeline.(*PipelineManager).ensureRemote(0xc00013e0c0), {0x100b7c0e8, 0xc00056e870}, {0xc000038154?, 0x2d?}, {0x100a32993?, 0xc0006b2280?})
        /Users/runner/work/1/s/cli/azd/pkg/commands/pipeline/pipeline_manager.go:146 +0xd1
[github.com/azure/azure-dev/cli/azd/pkg/commands/pipeline.(*PipelineManager).getGitRepoDetails(0xc00013e0c0](http://github.com/azure/azure-dev/cli/azd/pkg/commands/pipeline.(*PipelineManager).getGitRepoDetails(0xc00013e0c0), {0x100b7c0e8, 0xc00056e870})
        /Users/runner/work/1/s/cli/azd/pkg/commands/pipeline/pipeline_manager.go:171 +0x1c5
[github.com/azure/azure-dev/cli/azd/pkg/commands/pipeline.(*PipelineManager).Configure(0xc00013e0c0](http://github.com/azure/azure-dev/cli/azd/pkg/commands/pipeline.(*PipelineManager).Configure(0xc00013e0c0), {0x100b7c0e8, 0xc00056e870})
        /Users/runner/work/1/s/cli/azd/pkg/commands/pipeline/pipeline_manager.go:306 +0x245
[github.com/azure/azure-dev/cli/azd/cmd.(*pipelineConfigAction).Run(0xc00068e2a0](http://github.com/azure/azure-dev/cli/azd/cmd.(*pipelineConfigAction).Run(0xc00068e2a0), {0x100b7c0e8, 0xc00056e870})
        /Users/runner/work/1/s/cli/azd/cmd/pipeline.go:153 +0x1a5
[github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1({0x100b7c0e8](http://github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1(%7B0x100b7c0e8)?, 0xc00056e870?})
        /Users/runner/work/1/s/cli/azd/cmd/middleware/middleware.go:109 +0x23e
[github.com/azure/azure-dev/cli/azd/cmd/middleware.(*TelemetryMiddleware).Run(0xc0006a4350](http://github.com/azure/azure-dev/cli/azd/cmd/middleware.(*TelemetryMiddleware).Run(0xc0006a4350), {0x100b7c0e8, 0xc0004fc570}, 0xc00054a7c0)
        /Users/runner/work/1/s/cli/azd/cmd/middleware/telemetry.go:40 +0x175
[github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1({0x100b7c0e8](http://github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1(%7B0x100b7c0e8), 0xc0004fc570})
        /Users/runner/work/1/s/cli/azd/cmd/middleware/middleware.go:107 +0x1f2
[github.com/azure/azure-dev/cli/azd/cmd/middleware.(*DebugMiddleware).Run(0xc000120678](http://github.com/azure/azure-dev/cli/azd/cmd/middleware.(*DebugMiddleware).Run(0xc000120678), {0x100b7c0e8, 0xc0004fc570}, 0xc00054a7c0)
        /Users/runner/work/1/s/cli/azd/cmd/middleware/debug.go:48 +0x2b0
[github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1({0x100b7c0e8](http://github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1(%7B0x100b7c0e8), 0xc0004fc570})
        /Users/runner/work/1/s/cli/azd/cmd/middleware/middleware.go:107 +0x1f2
[github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction(0xc00007ff60](http://github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction(0xc00007ff60), {0x100b7c0e8, 0xc0004fc570}, 0x1008510e0?, {0x100b72fa0?, 0xc00068e2a0})
        /Users/runner/work/1/s/cli/azd/cmd/middleware/middleware.go:113 +0x23d
[github.com/azure/azure-dev/cli/azd/cmd.(*CobraBuilder).configureActionResolver.func1(0xc000485900](http://github.com/azure/azure-dev/cli/azd/cmd.(*CobraBuilder).configureActionResolver.func1(0xc000485900), {0xc000506260, 0x0, 0x2})
        /Users/runner/work/1/s/cli/azd/cmd/cobra_builder.go:132 +0x426
[github.com/spf13/cobra.(*Command).execute(0xc000485900](http://github.com/spf13/cobra.(*Command).execute(0xc000485900), {0xc000506240, 0x2, 0x2})
        /Users/runner/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:856 +0x67c
[github.com/spf13/cobra.(*Command).ExecuteC(0xc0003d8a00)](http://github.com/spf13/cobra.(*Command).ExecuteC(0xc0003d8a00))
        /Users/runner/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:974 +0x3bd
[github.com/spf13/cobra.(*Command).Execute(...)](http://github.com/spf13/cobra.(*Command).Execute(...))
        /Users/runner/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:902
[github.com/spf13/cobra.(*Command).ExecuteContext(0xc000036000](http://github.com/spf13/cobra.(*Command).ExecuteContext(0xc000036000)?, {0x100b7c078?, 0xc00003c098?})
        /Users/runner/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:895 +0x4a
main.main()
        /Users/runner/work/1/s/cli/azd/main.go:57 +0x159 
weikanglim commented 1 year ago

Hi @ardeshir, sorry to see that you're having issues.

In your local repository where you're running azd pipeline config --provider azdo, can you also run git remote get-url --all origin and provide the results?

The output should look like: git@ssh.dev.azure.com:v3/<project collection>/<project>/<repo> for example.

ardeshir commented 1 year ago

$ git remote get-url --all origin git@ssh.dev.azure.com:v3/fsdi/TechOps/CDS-Azure-Search-OpenAi

weikanglim commented 1 year ago

@ardeshir Thanks for that. I had looked at the code briefly, but couldn't find the immediate coding error when I confused myself. I can now confirm that it is indeed a bug that affects SSH URIs.

I hope you're not blocked by this. If you are, the quickest workaround is probably to switch to HTTPS when cloning the repository.

@vhvb1989 I was able to get a minimal repro for the panic by commenting out lines 195 and 197 below (to trigger the parsing of project name and repository name into IDs), then rerunning the tests in azdo_provider_test.go.

https://github.com/Azure/azure-dev/blob/9cbad62811cbae78f18698253e126e7ee3a8526d/cli/azd/pkg/commands/pipeline/azdo_provider_test.go#L194-L197

I think we need to adjust the parsing logic for handling SSH URIs.

vhvb1989 commented 1 year ago

ssh doesn't work on azd for azdo. All the connection is done with a PAT.

You can remove your local origin remote (git remote remove origin) and then run azd pipeline config to set the origin again. azd will ask you if you want to create a new repo or use existing. But azd will use a PAT and not ssh.

Another option is you run azd pipeline config --provider azdo --remote-name foo . This will ignore your origin remote and will set up a new foo remote for you

ardeshir commented 1 year ago

Thanks Wei & Victor,

I am not blocked, I was able to manually create az azdo pipeline, and work on deploying the infra appropriately with CI/CD. But I wanted to pass along the information/stack trace in case it was helpful to others and this project.

This new tool (azd) is a game changer, for devs with some infra control &/or knowledge. Thank you for all the work you’re doing.

Looking forward to this projects growth and success in the future. I am definitely impressed, and will do my best to contribute.

cheers

On Fri, Apr 7, 2023 at 7:03 PM Victor Vazquez @.***> wrote:

ssh doesn't work on azd for azdo. All the connection is done with a PAT.

You can remove your local origin remote (git remote remove origin) and then run azd pipeline config to set the origin again. azd will ask you if you want to create a new repo or use existing. But azd will use a PAT and not ssh.

Another option is you run azd pipeline config --provider azdo --remote-name foo . This will ignore your origin remote and will set up a new foo remote for you

— Reply to this email directly, view it on GitHub https://github.com/Azure/azure-dev/issues/1896#issuecomment-1500732288, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAQCDQ63OBUB7KUNDZLXVTXACTOTANCNFSM6AAAAAAWVZ266M . You are receiving this because you were mentioned.Message ID: @.***>

-- ardeshir.io @. github.com/ardeshir @.