Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/artifacts-helper/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,21 @@ This ensures any custom scripting in place during Codespaces build process will
The shim scripts (e.g., `dotnet`, `npm`, `nuget`) now include a wait mechanism for the Azure DevOps authentication helper. When invoked, these scripts will:

1. Wait up to 3 minutes for the `ado-auth-helper` to become available (configurable via `MAX_WAIT` environment variable)
2. Display progress indicators every 20 seconds while waiting
2. Display progress indicators every 20 seconds while waiting (only when `ARTIFACTS_HELPER_VERBOSE=true`)
3. Continue execution once authentication is successful
4. **Continue with the underlying command even if authentication is not available** after the timeout

By default, the authentication process runs silently. To enable verbose logging (useful for troubleshooting), set the `ARTIFACTS_HELPER_VERBOSE` environment variable to `true`:

```bash
export ARTIFACTS_HELPER_VERBOSE=true
```

When verbose mode is enabled, you will see step-by-step messages like:
- `::step::Waiting for AzDO Authentication Helper...`
- `::step::Running ado-auth-helper get-access-token...`
- `::step::✓ Access token retrieved successfully`

This ensures that package restore operations can proceed even if there's a slight delay in the authentication helper installation, which can occur in some codespace initialization scenarios. Commands will still execute without authentication, though they may fail to access private Azure Artifacts feeds.

The scripts are designed to be sourced safely, meaning they won't terminate the calling shell if authentication fails - they will simply return an error code and allow the underlying tool to execute. This allows you to work with public packages or other package sources even when Azure Artifacts authentication is unavailable.
Expand Down
2 changes: 1 addition & 1 deletion src/artifacts-helper/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Azure Artifacts Credential Helper",
"id": "artifacts-helper",
"version": "3.0.1",
"version": "3.0.2",
"description": "Configures Codespace to authenticate with Azure Artifact feeds",
"options": {
"nugetURIPrefixes": {
Expand Down
27 changes: 22 additions & 5 deletions src/artifacts-helper/scripts/auth-ado.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
#!/bin/bash

# Helper function to conditionally log messages
# Messages are only shown if ARTIFACTS_HELPER_VERBOSE is set to "true"
log_step() {
if [ "${ARTIFACTS_HELPER_VERBOSE}" = "true" ]; then
echo "::step::$1"
fi
}

log_message() {
if [ "${ARTIFACTS_HELPER_VERBOSE}" = "true" ]; then
echo "$1"
fi
}

# If ACTIONS_ID_TOKEN_REQUEST_URL is set, we're in a GitHub Actions environment
# Skip Azure DevOps authentication and just execute the real command
if [ -n "${ACTIONS_ID_TOKEN_REQUEST_URL}" ]; then
echo "::step::GitHub Actions environment detected, skipping Azure DevOps authentication"
log_step "GitHub Actions environment detected, skipping Azure DevOps authentication"
return 0
fi

echo "::step::Waiting for AzDO Authentication Helper..."
log_step "Waiting for AzDO Authentication Helper..."

# Wait up to 3 minutes for the ado-auth-helper to be installed
# Can be overridden via environment variable for testing
Expand All @@ -16,22 +30,25 @@ ELAPSED=0

while [ $ELAPSED -lt $MAX_WAIT ]; do
if [ -f "${HOME}/ado-auth-helper" ]; then
echo "::step::Running ado-auth-helper get-access-token..."
log_step "Running ado-auth-helper get-access-token..."
ARTIFACTS_ACCESSTOKEN=$(${HOME}/ado-auth-helper get-access-token)
echo "::step::✓ Access token retrieved successfully"
log_step "✓ Access token retrieved successfully"
# Return 0 to indicate successful authentication
return 0
fi
sleep 2
ELAPSED=$((ELAPSED + 2))

# Progress indicator every 20 seconds
if [ $((ELAPSED % 20)) -eq 0 ]; then
echo " Still waiting... (${ELAPSED}s elapsed)"
log_message " Still waiting... (${ELAPSED}s elapsed)"
fi
done

# Timeout reached - continue without authentication
# Always show timeout warnings regardless of verbose setting, as this indicates a potential issue
echo "::warning::AzDO Authentication Helper not found after ${MAX_WAIT} seconds"
echo "Expected location: ${HOME}/ado-auth-helper"
echo "Continuing without Azure Artifacts authentication..."
# Return 1 to indicate authentication was not successful, but don't exit (allow sourcing script to continue)
return 1
Loading