Skip to content
Permalink
Browse files

Set permissions to Jenkins-user, using the Library

Change-Id: I95c74dedc89da2d7121d581b2afcb8fca389aae9
  • Loading branch information
AZurhake committed Nov 29, 2019
1 parent 01b7a1d commit b72aae5233600d6348c0a2147e58dcb3766cb6d5
@@ -1,3 +1,24 @@
// The following code adds libraries to the Pipeline script
// Functions from libraries can be run by calling file-basename.functionaname()
// If you need to adjust the loading of the library, please code your changes in
// buildscripts/scripts/ on file jenkins-lib-loader/jenkins-template.groovy and run
// jenkins-lib-loader/update-jenkins-lib-loading.sh
// check the results and commit
node {
stage('Load Jenkins Libs') {
def LIB = [
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: [[$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [[path: 'vars'],
[path: 'buildscripts/scripts/vars']]],
[$class: 'CloneOption', depth: 0, noTags: true, reference: '', shallow: true]],
userRemoteConfigs: scm.userRemoteConfigs
]
library identifier: 'jenkins-libs@version', retriever: legacySCM(LIB)
}
}
// jenkins-libs loaded
import java.text.SimpleDateFormat

properties([
@@ -50,6 +71,8 @@ try {
DISTRO_LIST.each { DISTRO ->
DOCKER_BUILDS[DISTRO] = {
node {
def JENKINS_USER = id.getUser('jenkins')
def JENKINS_GROUP = id.getGroup('jenkins')
docker.withRegistry(DOCKER_REGISTRY, 'nexus') {
docker.image(DISTRO + '-os-image').pull()
docker.image(DISTRO + '-os-image').inside("-u 0:0 --ulimit nofile=1024:1024 -v /bauwelt/download/$CMK_VERSION:/bauwelt/download/$CMK_VERSION:ro -v $TEST_DATA:$TEST_DATA --init --privileged --network ci_local-infra --hostname ${DISTRO}") {
@@ -145,7 +168,7 @@ try {
rm -rf $DISTRO
mkdir -p $DISTRO
cp /omd/sites/${OMD_SITE}/junit.xml $DISTRO/
chown -R 112:120 $DISTRO
id.setOwner(${JENKINS_USER}, ${JENKINS_GROUP}, $DISTRO)
"""
stash name: "$DISTRO-results", includes: "$DISTRO/**/*"
// Unmount is clean solution, unfortunately it often fails
@@ -1,3 +1,24 @@
// The following code adds libraries to the Pipeline script
// Functions from libraries can be run by calling file-basename.functionaname()
// If you need to adjust the loading of the library, please code your changes in
// buildscripts/scripts/ on file jenkins-lib-loader/jenkins-template.groovy and run
// jenkins-lib-loader/update-jenkins-lib-loading.sh
// check the results and commit
node {
stage('Load Jenkins Libs') {
def LIB = [
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: [[$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [[path: 'vars'],
[path: 'buildscripts/scripts/vars']]],
[$class: 'CloneOption', depth: 0, noTags: true, reference: '', shallow: true]],
userRemoteConfigs: scm.userRemoteConfigs
]
library identifier: 'jenkins-libs@version', retriever: legacySCM(LIB)
}
}
// jenkins-libs loaded
import java.text.SimpleDateFormat

properties([
@@ -56,8 +77,8 @@ try {
DISTRO_LIST.each { DISTRO ->
DOCKER_BUILDS[DISTRO] = {
node {
def JENKINS_USER = sh(script: 'id -u jenkins', returnStdout: true).trim()
def JENKINS_GROUP = sh(script: 'id -g jenkins', returnStdout: true).trim()
def JENKINS_USER = id.getUser('jenkins')
def JENKINS_GROUP = id.getGroup('jenkins')
docker.withRegistry(DOCKER_REGISTRY, 'nexus') {
docker.image(DISTRO + '-os-image').pull()
docker.image(DISTRO + '-os-image').inside("-u 0:0 --ulimit nofile=1024:1024 -v /bauwelt/download/$CMK_VERSION:/bauwelt/download/$CMK_VERSION:ro -v $TEST_DATA:$TEST_DATA --init --privileged --network ci_local-infra --hostname ${DISTRO}") {
@@ -154,7 +175,7 @@ try {
mkdir -p $DISTRO
cp /omd/sites/${OMD_SITE}/junit.xml $DISTRO/
cp -r /omd/sites/${OMD_SITE}/var/log $DISTRO/
chown -R ${JENKINS_USER}:${JENKINS_GROUP} $DISTRO
id.setOwner(${JENKINS_USER}, ${JENKINS_GROUP}, $DISTRO)
"""
stash name: "$DISTRO-results", includes: "$DISTRO/**/*"
// Unmount is clean solution, unfortunately it often fails
@@ -0,0 +1,9 @@
def getUser(USER_NAME) {
return sh(script: "id -u ${USER_NAME}", returnStdout: true).trim()
}
def getGroup(GROUP_NAME) {
return sh(script: "id -u ${GROUP_NAME}", returnStdout: true).trim()
}
def setOwner(USER_ID, GROUP_ID, PATH) {
sh(script: "chown -R ${USER_ID}:${GROUP_ID} ${PATH}")
}

0 comments on commit b72aae5

Please sign in to comment.
You can’t perform that action at this time.