Skip to content

AWS EC2 Azure DevOps Agent Not Starting Automatically in Auto Scaling Group

0

Hi everyone.

I'm trying to automate the Azure DevOps agent startup on an EC2 instance within an Auto Scaling group using a user data script. The script successfully creates the myagent directory, and downloads the agent but it seems that something is not working well with configuring it. It successfully extracts the vsts-agent-linux-x64-3.246.0.tar.gz but it seems that the rest of the commands are not been executed.

This is the script that I use in User Data section in the Auto Scaling Group:

#!/bin/bash cd /home/ubuntu

mkdir myagent cd myagent

wget https://vstsagentpackage.azureedge.net/agent/3.246.0/vsts-agent-linux-x64-3.246.0.tar.gz

tar zxvf vsts-agent-linux-x64-3.246.0.tar.gz

chmod +x config.sh

./config.sh --unattended --url "https://dev.azure.com/exampleorg554" --auth PAT --token "123456789abccd" --pool "my-tst-pool" --agent $(hostname) --replace

sudo ./svc.sh install

sudo ./svc.sh start

Any ideas?

2 Answers
0
Accepted Answer

The issue you're experiencing with your Azure DevOps agent not starting automatically in an AWS EC2 Auto Scaling group could be due to a few factors. Let's analyze the potential problems and suggest some solutions:

  1. User Data Execution Context: User data scripts in EC2 instances run as the root user. Your script is trying to operate in the /home/ubuntu directory, which might not exist or be accessible when the script runs. Consider changing the working directory to a more universally accessible location, like /opt or /tmp.

  2. Permissions: Ensure that the EC2 instance has the necessary permissions to download and execute the agent. You might need to adjust the IAM role associated with the instance to allow these actions.

  3. Environment Variables: The agent configuration might require certain environment variables that aren't set in the context of the user data script execution. You may need to explicitly set these variables in your script.

  4. Networking: Verify that the EC2 instance has internet access to download the agent package and communicate with Azure DevOps.

  5. Error Logging: Add error logging to your script to capture any issues that occur during execution. You can redirect output to a log file for debugging:

    #!/bin/bash
    exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
  6. Wait for Cloud-Init: Your script might be running before cloud-init has finished. Add a wait for cloud-init at the beginning of your script:

    #!/bin/bash
    cloud-init status --wait
  7. Run as a Specific User: Consider running the agent configuration and installation as the ubuntu user:

    sudo -u ubuntu ./config.sh ...
  8. Service Installation: The svc.sh commands at the end of your script might need to be run with elevated privileges. Ensure you're using sudo for these commands.

By addressing these potential issues, you should be able to get your Azure DevOps agent starting automatically within your Auto Scaling group. Remember to test your changes incrementally and monitor the instance logs for any errors during the startup process.

Sources
Use OpenID Connect with AWS Toolkit for Azure DevOps to perform AWS CodeDeploy deployments | AWS DevOps Blog

answered 2 years ago

0

solution 7 did the trick.

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.