Build Component
The build component provides standardized build configuration for your GitLab CI / CD pipelines.
Usageโ
Include the build component in your .gitlab - ci.yml
:
include:
- component: [COMPONENT_REGISTRY] / [email protected]
inputs:
build_command: 'npm run build'
build_output: 'dist'
```text
## Configuration
### Required Inputs
| Input | Description | Default |
| --------------- | --------------------------- | ------- |
| `build_command`| Command to run for building | None |
### Optional Inputs
| Input | Description | Default |
| ------------------- | ------------------------------------ | ----------------------- |
|`build_output`| Directory containing build artifacts |`dist`|
|`node_version`| Node.js version to use |`18`|
|`npm_token`| NPM authentication token | None |
|`cache_key`| Custom cache key |`[CI_COMMIT_REF_SLUG]`|
|`pre_build_script`| Script to run before build | None |
|`post_build_script`| Script to run after build | None |
## Examples
### Basic Usage
```yaml
build:
extends: .build
variables:
BUILD_COMMAND: 'npm run build'
```text
### Advanced Configuration
```yaml
build:
extends: .build
variables:
BUILD_COMMAND: 'npm run build:prod'
BUILD_OUTPUT: 'build'
NODE_VERSION: '20'
PRE_BUILD_SCRIPT: 'npm run clean'
POST_BUILD_SCRIPT: 'npm run test:e2e'
```text
### Multiple Build Jobs
```yaml
build - app:
extends: .build
variables:
BUILD_COMMAND: 'npm run build:app'
BUILD_OUTPUT: 'dist / app'
build - docs:
extends: .build
variables:
BUILD_COMMAND: 'npm run build:docs'
BUILD_OUTPUT: 'dist / docs'
```text
## Cache Configuration
The build component uses GitLab's cache feature:
```yaml
cache:
key: [CI_COMMIT_REF_SLUG]
paths:
- node_modules/
- .npm/
- dist/
```text
## Artifacts
Build artifacts are automatically saved:
```yaml
artifacts:
paths:
- [BUILD_OUTPUT]
expire_in: 1 week
```text
## Environment Variables
### Available Variables
| Variable | Description |
| -------------- | ------------------------ |
| `CI_JOB_TOKEN`| GitLab CI token |
|`CI_REGISTRY`| GitLab registry URL |
|`NPM_TOKEN`| NPM authentication token |
|`NODE_ENV`| Node environment |
### Custom Variables
You can set custom environment variables:
```yaml
variables:
MY_VAR: 'value'
```text
## Best Practices
1. Version Management
- Pin component versions
- Use semantic versioning
- Document version changes
2. Build Optimization
- Use build caching
- Optimize build steps
- Clean old artifacts
3. Error Handling
- Add error checks
- Log build output
- Set timeout limits
## Troubleshooting
### Common Issues
1. Build Failures
- Check dependencies
- Verify build command
- Review error logs
2. Cache Problems
- Check cache paths
- Verify cache key
- Clear cache if needed
3. Artifact Issues
- Check permissions
- Verify paths
- Review size limits
## Support
Need help? Check our [Support Guide](.. / guide / support.md) or [create an issue](https://gitlab.bluefly.io / bluefly / internal - projects / llm / bfcicomponents/ - /issues).