From 96c60d0a833497b1814788c1f362457f376bf9b0 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Tue, 11 Feb 2020 20:27:42 +0000 Subject: [PATCH] ci(jenkins): enable fix-permissions to be executed without running make too (#16130) * ci(jenkins): enable fix-permissions to be executed without running make too * ci(jenkins): go modules are stored in the HOME path * ci(jenkins): fix permissions should run only if docker is enabled --- Jenkinsfile | 5 ++++- libbeat/scripts/Makefile | 3 +-- script/fix_permissions.sh | 11 +++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100755 script/fix_permissions.sh diff --git a/Jenkinsfile b/Jenkinsfile index 9a268376301..78096a2aa99 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -526,13 +526,16 @@ pipeline { } } -def makeTarget(context, target){ +def makeTarget(context, target, clean = true){ withGithubNotify(context: "${context}") { withBeatsEnv(){ sh(label: "Make ${target}", script: """ eval "\$(gvm use ${GO_VERSION} --format=bash)" make ${target} """) + if(clean) { + sh(script: 'script/fix_permissions.sh ${HOME}') + } } } } diff --git a/libbeat/scripts/Makefile b/libbeat/scripts/Makefile index 69a9d95e7f4..373b1a5e651 100755 --- a/libbeat/scripts/Makefile +++ b/libbeat/scripts/Makefile @@ -421,8 +421,7 @@ env-logs: ${DOCKER_COMPOSE} logs -f fix-permissions: - # Change ownership of all files inside /build folder from root/root to current user/group - docker run -v ${PWD}:/beat alpine:3.4 sh -c "find /beat -user 0 -exec chown -h $(shell id -u):$(shell id -g) {} \;" + sh ${ES_BEATS}/script/fix_permissions.sh "${PWD}" set_version: ## @packaging VERSION=x.y.z set the version of the beat to x.y.z ${ES_BEATS}/dev-tools/set_version ${VERSION} diff --git a/script/fix_permissions.sh b/script/fix_permissions.sh new file mode 100755 index 00000000000..fd65a7916b5 --- /dev/null +++ b/script/fix_permissions.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set +e +readonly LOCATION="${1?Please define the path where the fix permissions should run from}" + +if ! docker version ; then + echo "It requires Docker daemon to be installed and running" +else + set -e + # Change ownership of all files inside the specific folder from root/root to current user/group + docker run -v ${LOCATION}:/beat alpine:3.4 sh -c "find /beat -user 0 -exec chown -h $(id -u):$(id -g) {} \;" +fi