-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile_install_agent
50 lines (49 loc) · 2.09 KB
/
Jenkinsfile_install_agent
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
pipeline {
agent any
parameters {
password(name: 'TOKENID', defaultValue: 'SECRET', description: 'Enter a token for the Managed Agent')
}
stages {
stage('Create Managed Manifest') {
steps {
sh 'curl https://raw.githubusercontent.com/elastic/elastic-agent/main/deploy/kubernetes/elastic-agent-managed-kubernetes.yaml --output elastic-agent-managed-kubernetes.yaml'
sh "sed -i -e 's/token-id/${params.TOKENID}/g' elastic-agent-managed-kubernetes.yaml"
}
}
stage('Open PR') {
steps {
withCredentials([usernamePassword(credentialsId: 'GITHUB_PAT', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
//Preparing the
sh '''git clone https://github.com/gizas/automatek8s.git
mkdir -p automatek8s/manifests/
yes | cp -r elastic-agent-managed-kubernetes.yaml automatek8s/manifests/
'''
dir("automatek8s/manifests/"){
sh '''
pwd
git checkout TestBranch
git add ./
git config --global user.email "andreas.gkizas@elastic.co"
git config --global user.name "gizas"
git commit -m "Updating Manifest"
git push https://gizas:${PASSWORD}@github.com/gizas/automatek8s.git
'''
sh '''touch mytoken.txt
echo $PASSWORD > mytoken.txt
gh auth login --with-token < mytoken.txt
gh pr create --title "Automated PR" --body "Agent Automated PR" --base main --head TestBranch
gh pr merge --auto -m
'''
}
}
}
}
}
post {
success {
echo 'Removing Clone directory...'
sh 'pwd'
sh 'rm -rf automatek8s'
}
}
}