|
| 1 | +# GitHub Copilot Instructions for Azure Pipelines Agent |
| 2 | + |
| 3 | +This repository contains the Azure Pipelines Agent, a cross-platform build and release agent written in C# for .NET Core. When working with this codebase, follow these guidelines and use the provided development tools. |
| 4 | + |
| 5 | +## Project Structure |
| 6 | + |
| 7 | +- **Source Code**: All source code is in the `src/` directory |
| 8 | +- **Build Scripts**: Use `src/dev.sh` (Linux/macOS) or `src/dev.cmd` (Windows) |
| 9 | +- **Agent Layout**: Built agent is placed in `{root}/{runtime_id}/_layout` |
| 10 | +- **Documentation**: Available in `docs/` directory |
| 11 | + |
| 12 | +## Development Workflow |
| 13 | + |
| 14 | +### Initial Setup |
| 15 | +```bash |
| 16 | +# Clone and navigate to source |
| 17 | +git clone https://github.com/microsoft/azure-pipelines-agent |
| 18 | +cd ./src |
| 19 | + |
| 20 | +# First time setup - creates full agent layout |
| 21 | +./dev.sh layout |
| 22 | +``` |
| 23 | + |
| 24 | +### Build Commands |
| 25 | + |
| 26 | +All commands should be run from the `src/` directory: |
| 27 | + |
| 28 | +#### Linux/macOS |
| 29 | +```bash |
| 30 | +./dev.sh {command} [target_framework] [build_config] [runtime_id] [test_filters] |
| 31 | +``` |
| 32 | + |
| 33 | +#### Windows |
| 34 | +```cmd |
| 35 | +dev {command} [target_framework] [build_config] [runtime_id] [test_filters] |
| 36 | +``` |
| 37 | + |
| 38 | +### Available Commands |
| 39 | + |
| 40 | +| Command | Short | Description | |
| 41 | +|---------|-------|-------------| |
| 42 | +| `layout` | `l` | Create full agent layout in `{root}/{runtime_id}/_layout` (run first time) | |
| 43 | +| `build` | `b` | Build everything and update agent layout folder | |
| 44 | +| `test` | `t` | Build agent binaries and run unit tests for current platform | |
| 45 | +| `testl0` | `l0` | Run L0 (unit) tests only | |
| 46 | +| `testl1` | `l1` | Run L1 (integration) tests only | |
| 47 | +| `package` | `p` | Create distribution packages | |
| 48 | +| `hash` | | Generate hash files | |
| 49 | +| `report` | | Generate test reports | |
| 50 | +| `lint` | | Run code linting | |
| 51 | +| `lint-verify` | | Verify linting rules | |
| 52 | + |
| 53 | +### Normal Development Flow |
| 54 | +```bash |
| 55 | +# 1. Initial layout (first time only) |
| 56 | +./dev.sh layout |
| 57 | + |
| 58 | +# 2. Make code changes |
| 59 | +# ... edit files ... |
| 60 | + |
| 61 | +# 3. Build and test |
| 62 | +./dev.sh build |
| 63 | +./dev.sh test |
| 64 | + |
| 65 | +# 4. Commit changes |
| 66 | +git add . |
| 67 | +git commit -m "Your changes" |
| 68 | +git push |
| 69 | +``` |
| 70 | + |
| 71 | +## Project Details |
| 72 | + |
| 73 | +### Technology Stack |
| 74 | +- **Language**: C# (.NET Core) |
| 75 | +- **Target Framework**: net6.0 (default), net8.0 supported |
| 76 | +- **Platforms**: Windows (x64, x86, ARM64), macOS (x64, ARM64), Linux (x64, ARM) |
| 77 | +- **Build System**: MSBuild with custom scripts |
| 78 | + |
| 79 | +### Key Components |
| 80 | +- **Agent.Listener**: Main agent listener service |
| 81 | +- **Agent.Worker**: Task execution worker |
| 82 | +- **Agent.PluginHost**: Plugin hosting environment |
| 83 | +- **Agent.Plugins**: Built-in plugins |
| 84 | +- **Agent.Sdk**: SDK for agent development |
| 85 | + |
| 86 | +### Dependencies |
| 87 | +- **.NET SDK**: Automatically downloaded if not present |
| 88 | +- **Git**: Required for development (Git for Windows on Windows) |
| 89 | +- **Node.js**: For certain pipeline tasks |
| 90 | + |
| 91 | +## Testing |
| 92 | + |
| 93 | +### Test Types |
| 94 | +- **L0 Tests**: Unit tests (`./dev.sh testl0`) |
| 95 | +- **L1 Tests**: Integration tests (`./dev.sh testl1`) |
| 96 | + |
| 97 | +### Test Filters |
| 98 | +Add custom test filters as the 5th parameter: |
| 99 | +```bash |
| 100 | +./dev.sh test net6.0 Debug osx-arm64 "TestCategory=YourCategory" |
| 101 | +``` |
| 102 | + |
| 103 | +## Debugging |
| 104 | + |
| 105 | +### Debug Mode |
| 106 | +Run the agent with debug mode: |
| 107 | +```bash |
| 108 | +./config.sh --debug |
| 109 | +./run.sh --debug |
| 110 | +``` |
| 111 | + |
| 112 | +### Environment Variables for Debugging |
| 113 | +- `VSTSAGENT_DEBUG_TASK`: Debug specific tasks by ID or name+version |
| 114 | + |
| 115 | +## Build Configurations |
| 116 | + |
| 117 | +### Available Configurations |
| 118 | +- **Debug**: Development builds with debug symbols |
| 119 | +- **Release**: Production builds optimized for performance |
| 120 | + |
| 121 | +### Runtime IDs |
| 122 | +Common runtime identifiers: |
| 123 | +- `win-x64`, `win-x86`, `win-arm64` |
| 124 | +- `osx-x64`, `osx-arm64` |
| 125 | +- `linux-x64`, `linux-arm`, `linux-arm64` |
| 126 | +- `rhel.6-x64` |
| 127 | + |
| 128 | +### Package Types |
| 129 | +- `agent` (default): Full agent package |
| 130 | +- `pipelines-agent`: Pipelines-specific package (excludes Node 6/10) |
| 131 | + |
| 132 | +## Code Style |
| 133 | + |
| 134 | +Follow the [.NET Foundation coding guidelines](https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/coding-style.md): |
| 135 | + |
| 136 | +- Use PascalCase for public members |
| 137 | +- Use camelCase for private fields |
| 138 | +- Use meaningful names |
| 139 | +- Keep methods focused and small |
| 140 | +- Include XML documentation for public APIs |
| 141 | + |
| 142 | +## Common Tasks |
| 143 | + |
| 144 | +### Adding New Features |
| 145 | +1. Create/modify source files in appropriate `src/` subdirectories |
| 146 | +2. Add unit tests in `src/Test/` |
| 147 | +3. Build and test: `./dev.sh build && ./dev.sh test` |
| 148 | +4. Update documentation if needed |
| 149 | + |
| 150 | +### Troubleshooting Build Issues |
| 151 | +- **"unzip not found"**: Install unzip (`sudo apt install unzip` on WSL) |
| 152 | +- **Missing dependencies**: Run `./dev.sh layout` to restore |
| 153 | +- **Test failures**: Check platform-specific test filters |
| 154 | + |
| 155 | +### Working with Agent Layout |
| 156 | +The built agent in `_layout/` can be used for: |
| 157 | +- Local testing and debugging |
| 158 | +- Manual agent installation |
| 159 | +- Testing pipeline integration |
| 160 | + |
| 161 | +To configure and run the built agent: |
| 162 | +```bash |
| 163 | +cd {root}/{runtime_id}/_layout |
| 164 | +./config.sh |
| 165 | +./run.sh |
| 166 | +``` |
| 167 | + |
| 168 | +## Best Practices |
| 169 | + |
| 170 | +1. **Always run layout first** when starting development |
| 171 | +2. **Build before testing** to ensure latest changes are included |
| 172 | +3. **Run tests** before committing to catch regressions |
| 173 | +4. **Use appropriate runtime ID** for your target platform |
| 174 | +5. **Follow the normal dev flow** for consistent results |
| 175 | + |
| 176 | +## Additional Resources |
| 177 | + |
| 178 | +- [Contributing Guide](../docs/contribute.md) |
| 179 | +- [Azure DevOps Agent Documentation](https://docs.microsoft.com/azure/devops/pipelines/agents/) |
| 180 | +- [Self-hosted Agent Installation](https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/windows-agent?view=azure-devops) |
0 commit comments