# install jenkins ``` kubectl create -f serviceaccount.yaml helm install --name jenkins --set rbac.create=true,master.runAsUser=1000,master.fsGroup=1000 stable/jenkins ```
[root@k7smaster jenkins]# cat Jenkinsfile.build pipeline { agent { kubernetes { label 'helm-pod' containerTemplate { name 'helm' image 'wardviaene/helm-s3' ttyEnabled true command 'cat' } } } stages { stage('Run helm') { steps { container('helm') { git url: 'git://github.com/wardviaene/kubernetes-course.git', branch: 'master' sh ''' HELM_BUCKET=helm-rytcufor PACKAGE=demo-chart export AWS_REGION=eu-west-1 cp -r /home/helm/.helm ~ helm repo add my-charts s3://${HELM_BUCKET}/charts cd helm/${PACKAGE} helm dependency update helm package . helm s3 push --force ${PACKAGE}-*.tgz my-charts ''' } } } } }
复制jenkins pipline 进来
相同的创建部署pipline 脚本
Jenkinsfile.deploy pipeline { agent { kubernetes { label 'helm-pod' serviceAccount 'jenkins-helm' containerTemplate { name 'helm-pod' image 'wardviaene/helm-s3' ttyEnabled true command 'cat' } } } stages { stage('Run helm') { steps { container('helm-pod') { git url: 'git://github.com/wardviaene/kubernetes-course.git', branch: 'master' sh ''' HELM_BUCKET=helm-rytcufor PACKAGE=demo-chart export AWS_REGION=eu-west-1 cp -r /home/helm/.helm ~ helm repo add my-charts s3://${HELM_BUCKET}/charts DEPLOYED=$(helm list |grep -E "^${PACKAGE}" |grep DEPLOYED |wc -l) if [ $DEPLOYED == 0 ] ; then helm install --name ${PACKAGE} my-charts/${PACKAGE} else helm upgrade ${PACKAGE} my-charts/${PACKAGE} fi echo "deployed!" ''' } } } } }