Skip to content

Commit 07d8b0f

Browse files
committed
Add single-stage CI pipeline example
1 parent d72c7ea commit 07d8b0f

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

pipelines/single-stage-ci.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Single-Stage CI Pipeline for Node.js
2+
# Teaching example for basic continuous integration
3+
4+
trigger:
5+
branches:
6+
include:
7+
- master
8+
- main
9+
paths:
10+
include:
11+
- nodeapp-1/*
12+
13+
pool:
14+
vmImage: 'ubuntu-latest'
15+
16+
variables:
17+
nodeVersion: '18.x'
18+
artifactName: 'drop'
19+
20+
steps:
21+
# Step 1: Setup Node.js environment
22+
- task: NodeTool@0
23+
displayName: 'Install Node.js $(nodeVersion)'
24+
inputs:
25+
versionSpec: $(nodeVersion)
26+
27+
# Step 2: Install dependencies
28+
- script: |
29+
echo "Installing npm dependencies..."
30+
npm ci
31+
displayName: 'npm install'
32+
workingDirectory: nodeapp-1
33+
34+
# Step 3: Run linting
35+
- script: |
36+
echo "Running ESLint..."
37+
npm run lint || echo "No lint script found, skipping..."
38+
displayName: 'Run linting'
39+
workingDirectory: nodeapp-1
40+
continueOnError: true
41+
42+
# Step 4: Run unit tests
43+
- script: |
44+
echo "Running tests..."
45+
npm test
46+
displayName: 'Run unit tests'
47+
workingDirectory: nodeapp-1
48+
49+
# Step 5: Generate test results
50+
- task: PublishTestResults@2
51+
displayName: 'Publish test results'
52+
inputs:
53+
testResultsFormat: 'JUnit'
54+
testResultsFiles: '**/test-results.xml'
55+
searchFolder: nodeapp-1
56+
condition: succeededOrFailed()
57+
58+
# Step 6: Code coverage
59+
- script: |
60+
echo "Generating code coverage..."
61+
npm run coverage || echo "No coverage script found, skipping..."
62+
displayName: 'Generate code coverage'
63+
workingDirectory: nodeapp-1
64+
continueOnError: true
65+
66+
- task: PublishCodeCoverageResults@1
67+
displayName: 'Publish code coverage'
68+
inputs:
69+
codeCoverageTool: 'Cobertura'
70+
summaryFileLocation: 'nodeapp-1/coverage/cobertura-coverage.xml'
71+
condition: succeededOrFailed()
72+
73+
# Step 7: Build the application
74+
- script: |
75+
echo "Building application..."
76+
npm run build || npm run compile || echo "No build script, using source files..."
77+
displayName: 'Build application'
78+
workingDirectory: nodeapp-1
79+
80+
# Step 8: Create artifact
81+
- task: ArchiveFiles@2
82+
displayName: 'Archive application files'
83+
inputs:
84+
rootFolderOrFile: 'nodeapp-1'
85+
includeRootFolder: false
86+
archiveType: 'zip'
87+
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
88+
89+
# Step 9: Publish artifact
90+
- task: PublishBuildArtifacts@1
91+
displayName: 'Publish artifact'
92+
inputs:
93+
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
94+
ArtifactName: $(artifactName)
95+
publishLocation: 'Container'
96+
97+
# Success notification
98+
- script: |
99+
echo "✅ Build completed successfully!"
100+
echo "Build ID: $(Build.BuildId)"
101+
echo "Source branch: $(Build.SourceBranch)"
102+
echo "Commit: $(Build.SourceVersion)"
103+
displayName: 'Build summary'
104+
condition: succeeded()

0 commit comments

Comments
 (0)