Skip to content

Commit 59deac5

Browse files
Add files via upload
1 parent db9b41c commit 59deac5

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

azure-pipelines.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
trigger:
2+
- master # Change this to your branch
3+
4+
pool:
5+
name: sample # Self-hosted agent pool name
6+
demands:
7+
- Agent.Name -equals school # Ensuring the correct agent is used
8+
9+
variables:
10+
ACR_NAME: "sample" # Name of your Azure Container Registry
11+
IMAGE_NAME: "school" # Name of the Docker image
12+
IMAGE_TAG: "$(Build.BuildId)" # Unique tag for each build
13+
MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
14+
15+
stages:
16+
- stage: Build
17+
displayName: "Build Java and Docker Image"
18+
jobs:
19+
- job: BuildJob
20+
displayName: "Build and Package App"
21+
steps:
22+
23+
- task: Maven@3
24+
displayName: "Run Maven Clean Package"
25+
inputs:
26+
mavenPomFile: "pom.xml"
27+
goals: "clean package"
28+
publishJUnitResults: true
29+
options: "-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)"
30+
javaHomeOption: "JDKVersion"
31+
jdkVersionOption: "8"
32+
mavenVersionOption: "Default"
33+
mavenAuthenticateFeed: false
34+
35+
- script: |
36+
echo "Building Docker Image..."
37+
docker build -t $(ACR_NAME).azurecr.io/$(IMAGE_NAME):$(IMAGE_TAG) .
38+
displayName: "Build Docker Image"
39+
40+
- stage: Push
41+
displayName: "Push Docker Image to ACR"
42+
jobs:
43+
- job: PushJob
44+
displayName: "Push Image to Azure Container Registry"
45+
steps:
46+
47+
- task: AzureCLI@2
48+
displayName: "Login to ACR"
49+
inputs:
50+
azureSubscription: "azurerm"
51+
scriptType: "bash"
52+
scriptLocation: "inlineScript"
53+
inlineScript: |
54+
az acr login --name $(ACR_NAME)
55+
56+
- script: |
57+
echo "Pushing Docker image to ACR..."
58+
docker push $(ACR_NAME).azurecr.io/$(IMAGE_NAME):$(IMAGE_TAG)
59+
displayName: "Push Docker Image"

0 commit comments

Comments
 (0)