Building on the previous two documents, Creating Jenkins Slaves Dynamically on Kubernetes and Adding Windows Nodes to Kubernetes to Provide Dynamic Jenkins Build Agents, this document mainly attempts to dynamically provide Windows build agents on Kubernetes.
1. Adding Pipelines
For the Kubernetes and Jenkins integration part, refer to the two documents above; here we simply create two pipelines to test with.
- windows - the built-in Jenkins pipeline example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| /*
* Runs a build on a Windows pod.
* Tested in EKS: https://docs.aws.amazon.com/eks/latest/userguide/windows-support.html
*/
podTemplate(yaml: '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: jnlp
image: jenkins/inbound-agent:windowsservercore-1809
- name: shell
image: mcr.microsoft.com/powershell:preview-windowsservercore-1809
command:
- powershell
args:
- Start-Sleep
- 999999
nodeSelector:
kubernetes.io/os: windows
''') {
node(POD_LABEL) {
container('shell') {
powershell 'Get-ChildItem Env: | Sort Name'
}
}
}
|
Build using the dotnet image
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| pipeline {
agent {
kubernetes {
yaml """
apiVersion: v1
kind: Pod
metadata:
name: windows
spec:
containers:
- name: jnlp
image: jenkins/inbound-agent:windowsservercore-1809
tty: true
- name: windows-dotnet
image: mcr.microsoft.com/dotnet/core/sdk:2.1
tty: true
nodeSelector:
kubernetes.io/os: windows
"""
}
}
stages {
stage('Run on windows') {
steps {
container(name:'windows-dotnet'){
bat 'dotnet -h'
}
}
}
}
}
|
2. Viewing the Results




- Viewing the images downloaded by Windows
1
2
3
4
5
6
| docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mcr.microsoft.com/powershell preview-windowsservercore-1809 ff3a59b7e85e 3 days ago 5.24GB
mcr.microsoft.com/dotnet/core/sdk 2.1 4ca3f3cfa1e2 4 days ago 1.66GB
jenkins/inbound-agent windowsservercore-1809 45f5745f2aab 4 days ago 4.09GB
|
The Windows node absolutely must have a very large amount of disk space.
3. References