Doing Jenkins Declarative Pipeline,
So I'm looking for "Post" action that will send e-mail only if there is 1 file which exists and is biggger then 0kb.
Very similiar to bash function : if [-s]
I can do that in a bash script, but how is done in jenkins for POST BUILD:
See how is made in bash:
if [ -s "$file" ]
then
/usr/bin/mutt -s "Master Failed 3Days" $emails -a $file < /dev/null
exit 1
else
echo "$file is empty."
/usr/bin/mutt -s "Master Success 3Days" $emails_success -a $file < /dev/null
exit 0
fi
This approach is working:
1. You are doing a global variable with your shell script in stage
result = sh(script: '''
if [ -s "$file" ]
then
/usr/bin/mutt -s "Master Failed 3Days" $emails -a $file < /dev/null
echo 'found'
else
echo "$file is empty."
/usr/bin/mutt -s "Master Success 3Days" $emails_success -a $file < /dev/null
echo 'not'
fi
''', returnStdout: true).trim()
You are adding post definitions
post {
always {
script {
if (result.contains('found')) {
<your logic to sending email>
}
}
}
}
Related
I'm new to Jenkins.
I have a job with an "Execute Shell" Build trigger, and in that shell script i initiate some variables with values i take from some source.
I need to pass these values to a downstream job.
The values i want to pass are $IMG_NAME and $IMG_PATH from this shell script:
#!/bin/bash -x
whoami
echo "BASE_PATH: $BASE_PATH"
declare -A BRANCHES
for i in $(echo $BRANCHES_LIST | tr ',' '\n'); do BRANCHES[$i]= ; done
echo 'user' | sudo -S umount -rf /mnt/tlv-s-comp-prod/drops/
echo 'user' | sudo -S mount.nfs -o nolock,nfsvers=3 tlv-s-comp-prod:/export/drops /mnt/tlv-s-comp-prod/drops
ls /mnt/tlv-s-comp-prod/drops/
echo "cleanup workspace"
rm ${WORKSPACE}/*.txt &> /dev/null
i="0"
while [ $i -lt 6 ]
do
if [[ ${BASE_PATH} == *"Baseline"* ]]; then
unset BRANCHES[#]
declare -A BRANCHES
BRANCHES[Baseline]=
fi
for BRANCH in "${!BRANCHES[#]}"; do
echo "BRANCH: $BRANCH"
if [ $BRANCH == "Baseline" ]; then BRANCH=; fi
img_dir=$(ls -td -- ${BASE_PATH}/${BRANCH}/*/ | head -n 1)
echo "img_dir: $img_dir"
IMG_PATH=$(ls $img_dir*.rpm)
echo "IMG_PATH: $IMG_PATH"
cd $img_dir
IMG_NAME=$(ls *.rpm) > env.properties
if [ ! -z "$IMG_NAME" ]; then
if [ $(( $(date +%s) - $(stat -c %Z $IMG_PATH) )) -lt 10000800 ]; then
echo "IMG_NAME: ${IMG_NAME}"
#BRANCHES[$BRANCH]=$IMG_PATH
#echo "REG_OSA_SOFTSYNC_BUILD_IMG_FULL_PATH=${BRANCHES[$BRANCH]}" >> ${WORKSPACE}/$BRANCH.txt
echo "BRANCH_NAME=$BRANCH" >> ${WORKSPACE}/${BRANCH}_branch.txt
echo "REG_OSA_SOFTSYNC_BUILD_NAME=$BRANCH-$IMG_NAME" >> ${WORKSPACE}/${BRANCH}_branch.txt
else
echo "$IMG_NAME is out dated"
fi
else
echo "IMG_NAME is empty"
fi
BRANCH_NAME=""
done
$TEMP=$BRANCH_NAME
echo "TEMP: $TEMP"
if [ $(ls ${WORKSPACE}/*_branch.txt | wc -l) == $(echo ${#BRANCHES[#]}) ]; then break; fi
#for i in $(ls *_branch.txt); do i=$(echo $i | awk -F '_branch.txt' '{print $1}'); if [ $(echo ${!BRANCHES[#]} | grep $i | wc -l) == 0 ]; then state=1 break; fi done
i=$[$i+1]
sleep 1800
done
This is the "Trigger parameterized build on other projects" configuration:
I am implementing the SonarQube to my project. SonarQube server is up but when i am try to run the run-sonar-swift.sh script i got console error and i can't see the project on the console. SonarQube and SonarScanner added under the Application folder.
Here is my run-sonar-swift.sh script:
#!/bin/bash
#
# backelite-sonar-swift-plugin - Enables analysis of Swift and Objective-C projects into SonarQube.
# Copyright © 2015 Backelite (${email})
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
## INSTALLATION: Copy this script somewhere in your PATH
## USAGE: ./run-sonar-swift.sh
## DEBUG: ./run-sonar-swift.sh -v
## WARNING: edit your project parameters in sonar-project.properties rather than modifying this script
#
# Global parameters
SLATHER_CMD=slather
SWIFTLINT_CMD=swiftlint
TAILOR_CMD=tailor
XCPRETTY_CMD=xcpretty
LIZARD_CMD=lizard
XCODEBUILD_CMD=xcodebuild
trap "echo 'Script interrupted by Ctrl+C'; stopProgress; exit 1" SIGHUP SIGINT SIGTERM
function startProgress() {
while true
do
echo -n "."
sleep 5
done
}
function stopProgress() {
if [ "$vflag" = "" -a "$nflag" = "" ]; then
kill $PROGRESS_PID &>/dev/null
fi
}
function testIsInstalled() {
hash $1 2>/dev/null
if [ $? -eq 1 ]; then
echo >&2 "ERROR - $1 is not installed or not in your PATH"; exit 1;
fi
}
function readParameter() {
variable=$1
shift
parameter=$1
shift
eval $variable="\"$(sed '/^\#/d' sonar-project.properties | grep $parameter | tail -n 1 | cut -d '=' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')\""
}
# Run a set of commands with logging and error handling
function runCommand() {
# 1st arg: redirect stdout
# 2nd arg: command to run
# 3rd..nth arg: args
redirect=$1
shift
command=$1
shift
if [ "$nflag" = "on" ]; then
# don't execute command, just echo it
echo
if [ "$redirect" = "/dev/stdout" ]; then
if [ "$vflag" = "on" ]; then
echo "+" $command "$#"
else
echo "+" $command "$#" "> /dev/null"
fi
elif [ "$redirect" != "no" ]; then
echo "+" $command "$#" "> $redirect"
else
echo "+" $command "$#"
fi
elif [ "$vflag" = "on" ]; then
echo
if [ "$redirect" = "/dev/stdout" ]; then
set -x #echo on
$command "$#"
returnValue=$?
set +x #echo off
elif [ "$redirect" != "no" ]; then
set -x #echo on
$command "$#" > $redirect
returnValue=$?
set +x #echo off
else
set -x #echo on
$command "$#"
returnValue=$?
set +x #echo off
fi
if [[ $returnValue != 0 && $returnValue != 5 ]] ; then
stopProgress
echo "ERROR - Command '$command $#' failed with error code: $returnValue"
exit $returnValue
fi
else
if [ "$redirect" = "/dev/stdout" ]; then
$command "$#" > /dev/null
elif [ "$redirect" != "no" ]; then
$command "$#" > $redirect
else
$command "$#"
fi
returnValue=$?
if [[ $returnValue != 0 && $returnValue != 5 ]] ; then
stopProgress
echo "ERROR - Command '$command $#' failed with error code: $returnValue"
exit $returnValue
fi
echo
fi
}
## COMMAND LINE OPTIONS
vflag=""
nflag=""
unittests="on"
swiftlint="on"
tailor="on"
lizard="on"
oclint="on"
fauxpas="on"
sonarscanner=""
while [ $# -gt 0 ]
do
case "$1" in
-v) vflag=on;;
-n) nflag=on;;
-nounittests) unittests="";;
-noswiftlint) swiftlint="";;
-notailor) tailor="";;
-usesonarscanner) sonarscanner="on";;
--) shift; break;;
-*)
echo >&2 "Usage: $0 [-v]"
exit 1;;
*) break;; # terminate while loop
esac
shift
done
# Usage OK
echo "Running run-sonar-swift.sh..."
## CHECK PREREQUISITES
# sonar-project.properties in current directory
if [ ! -f sonar-project.properties ]; then
echo >&2 "ERROR - No sonar-project.properties in current directory"; exit 1;
fi
## READ PARAMETERS from sonar-project.properties
#.xcodeproj filename
projectFile=''; readParameter projectFile 'sonar.swift.project'
workspaceFile=''; readParameter workspaceFile 'sonar.swift.workspace'
# Count projects
if [[ ! -z "$projectFile" ]]; then
projectCount=$(echo $projectFile | sed -n 1'p' | tr ',' '\n' | wc -l | tr -d '[[:space:]]')
if [ "$vflag" = "on" ]; then
echo "Project count is [$projectCount]"
fi
fi
# Source directories for .swift files
srcDirs=''; readParameter srcDirs 'sonar.sources'
# The name of your application scheme in Xcode
appScheme=''; readParameter appScheme 'sonar.swift.appScheme'
# The app configuration to use for the build
appConfiguration=''; readParameter appConfiguration 'sonar.swift.appConfiguration'
# The name of your test scheme in Xcode
testScheme=''; readParameter testScheme 'sonar.swift.testScheme'
# The name of your binary file (application)
binaryName=''; readParameter binaryName 'sonar.swift.appName'
# Get the path of plist file
plistFile=`xcodebuild -showBuildSettings -project "${projectFile}" | grep -i 'PRODUCT_SETTINGS_PATH' -m 1 | sed 's/[ ]*PRODUCT_SETTINGS_PATH = //'`
# Number version from plist if no sonar.projectVersion
numVerionFromPlist=`defaults read ${plistFile} CFBundleShortVersionString`
# Read destination simulator
destinationSimulator=''; readParameter destinationSimulator 'sonar.swift.simulator'
# Read tailor configuration
tailorConfiguration=''; readParameter tailorConfiguration 'sonar.swift.tailor.config'
# The file patterns to exclude from coverage report
excludedPathsFromCoverage=''; readParameter excludedPathsFromCoverage 'sonar.swift.excludedPathsFromCoverage'
# Check for mandatory parameters
if [ -z "$projectFile" -o "$projectFile" = " " ] && [ -z "$workspaceFile" -o "$workspaceFile" = " " ]; then
echo >&2 "ERROR - sonar.swift.project or/and sonar.swift.workspace parameter is missing in sonar-project.properties. You must specify which projects (comma-separated list) are application code or which workspace and project to use."
exit 1
elif [ ! -z "$workspaceFile" ] && [ -z "$projectFile" ]; then
echo >&2 "ERROR - sonar.swift.workspace parameter is present in sonar-project.properties but sonar.swift.project and is not. You must specify which projects (comma-separated list) are application code or which workspace and project to use."
exit 1
fi
if [ -z "$srcDirs" -o "$srcDirs" = " " ]; then
echo >&2 "ERROR - sonar.sources parameter is missing in sonar-project.properties. You must specify which directories contain your .swift source files (comma-separated list)."
exit 1
fi
if [ -z "$appScheme" -o "$appScheme" = " " ]; then
echo >&2 "ERROR - sonar.swift.appScheme parameter is missing in sonar-project.properties. You must specify which scheme is used to build your application."
exit 1
fi
if [ "$unittests" = "on" ]; then
if [ -z "$destinationSimulator" -o "$destinationSimulator" = " " ]; then
echo >&2 "ERROR - sonar.swift.simulator parameter is missing in sonar-project.properties. You must specify which simulator to use."
exit 1
fi
fi
# if the appConfiguration is not specified then set to Debug
if [ -z "$appConfiguration" -o "$appConfiguration" = " " ]; then
appConfiguration="Debug"
fi
if [ "$vflag" = "on" ]; then
echo "Xcode project file is: $projectFile"
echo "Xcode workspace file is: $workspaceFile"
echo "Xcode application scheme is: $appScheme"
echo "Number version from plist is: $numVerionFromPlist"
if [ -n "$unittests" ]; then
echo "Destination simulator is: $destinationSimulator"
echo "Excluded paths from coverage are: $excludedPathsFromCoverage"
else
echo "Unit surefire are disabled"
fi
fi
## SCRIPT
# Start progress indicator in the background
if [ "$vflag" = "" -a "$nflag" = "" ]; then
startProgress &
# Save PID
PROGRESS_PID=$!
fi
# Create sonar-reports/ for reports output
if [ "$vflag" = "on" ]; then
echo 'Creating directory sonar-reports/'
fi
rm -rf sonar-reports
mkdir sonar-reports
# Extracting project information needed later
echo -n 'Extracting Xcode project information'
if [[ "$workspaceFile" != "" ]] ; then
buildCmdPrefix="-workspace $workspaceFile"
else
buildCmdPrefix="-project $projectFile"
fi
buildCmd=($XCODEBUILD_CMD clean build $buildCmdPrefix -scheme $appScheme)
if [[ ! -z "$destinationSimulator" ]]; then
buildCmd+=(-destination "$destinationSimulator" -destination-timeout 360 COMPILER_INDEX_STORE_ENABLE=NO)
fi
runCommand xcodebuild.log "${buildCmd[#]}"
#oclint-xcodebuild # Transform the xcodebuild.log file into a compile_command.json file
cat xcodebuild.log | $XCPRETTY_CMD -r json-compilation-database -o compile_commands.json
# Objective-C code detection
hasObjC="no"
compileCmdFile=compile_commands.json
minimumSize=3
actualSize=$(stat -f%z "$compileCmdFile")
echo "actual = $actualSize, min = $minimumSize"
if [ $actualSize -ge $minimumSize ]; then
hasObjC="yes"
fi
# Unit surefire and coverage
if [ "$unittests" = "on" ]; then
# Put default xml files with no surefire and no coverage...
echo "<?xml version='1.0' encoding='UTF-8' standalone='yes'?><testsuites name='AllTestUnits'></testsuites>" > sonar-reports/TEST-report.xml
echo "<?xml version='1.0' ?><!DOCTYPE coverage SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'><coverage><sources></sources><packages></packages></coverage>" > sonar-reports/coverage-swift.xml
echo -n 'Running surefire'
buildCmd=($XCODEBUILD_CMD clean build test)
if [[ ! -z "$workspaceFile" ]]; then
buildCmd+=(-workspace "$workspaceFile")
elif [[ ! -z "$projectFile" ]]; then
buildCmd+=(-project "$projectFile")
fi
buildCmd+=( -scheme "$appScheme" -configuration "$appConfiguration" -enableCodeCoverage YES)
if [[ ! -z "$destinationSimulator" ]]; then
buildCmd+=(-destination "$destinationSimulator" -destination-timeout 60)
fi
runCommand sonar-reports/xcodebuild.log "${buildCmd[#]}"
cat sonar-reports/xcodebuild.log | $XCPRETTY_CMD -t --report junit
mv build/reports/junit.xml sonar-reports/TEST-report.xml
echo '\nComputing coverage report\n'
# Build the --exclude flags
excludedCommandLineFlags=""
if [ ! -z "$excludedPathsFromCoverage" -a "$excludedPathsFromCoverage" != " " ]; then
echo $excludedPathsFromCoverage | sed -n 1'p' | tr ',' '\n' > tmpFileRunSonarSh2
while read word; do
excludedCommandLineFlags+=" -i $word"
done < tmpFileRunSonarSh2
rm -rf tmpFileRunSonarSh2
fi
if [ "$vflag" = "on" ]; then
echo "Command line exclusion flags for slather is:$excludedCommandLineFlags"
fi
firstProject=$(echo $projectFile | sed -n 1'p' | tr ',' '\n' | head -n 1)
slatherCmd=($SLATHER_CMD coverage)
if [[ ! -z "$binaryName" ]]; then
slatherCmd+=( --binary-basename "$binaryName")
fi
slatherCmd+=( --input-format profdata $excludedCommandLineFlags --cobertura-xml --output-directory sonar-reports)
if [[ ! -z "$workspaceFile" ]]; then
slatherCmd+=( --workspace "$workspaceFile")
fi
slatherCmd+=( --scheme "$appScheme" "$firstProject")
echo "${slatherCmd[#]}"
runCommand /dev/stdout "${slatherCmd[#]}"
mv sonar-reports/cobertura.xml sonar-reports/coverage-swift.xml
fi
# SwiftLint
if [ "$swiftlint" = "on" ]; then
if hash $SWIFTLINT_CMD 2>/dev/null; then
echo -n 'Running SwiftLint...'
# Build the --include flags
currentDirectory=${PWD##*/}
echo "$srcDirs" | sed -n 1'p' | tr ',' '\n' > tmpFileRunSonarSh
while read word; do
# Run SwiftLint command
$SWIFTLINT_CMD lint --path "$word" > sonar-reports/"$appScheme"-swiftlint.txt
done < tmpFileRunSonarSh
rm -rf tmpFileRunSonarSh
else
echo "Skipping SwiftLint (not installed!)"
fi
else
echo 'Skipping SwiftLint (test purposes only!)'
fi
# Tailor
if [ "$tailor" = "on" ]; then
if hash $TAILOR_CMD 2>/dev/null; then
echo -n 'Running Tailor...'
# Build the --include flags
currentDirectory=${PWD##*/}
echo "$srcDirs" | sed -n 1'p' | tr ',' '\n' > tmpFileRunSonarSh
while read word; do
# Run tailor command
$TAILOR_CMD $tailorConfiguration "$word" > sonar-reports/"$appScheme"-tailor.txt
done < tmpFileRunSonarSh
rm -rf tmpFileRunSonarSh
else
echo "Skipping Tailor (not installed!)"
fi
else
echo 'Skipping Tailor!'
fi
if [ "$oclint" = "on" ] && [ "$hasObjC" = "yes" ]; then
echo -n 'Running OCLint...'
# Options
maxPriority=10000
longLineThreshold=250
# Build the --include flags
currentDirectory=${PWD##*/}
echo "$srcDirs" | sed -n 1'p' | tr ',' '\n' > tmpFileRunSonarSh
while read word; do
includedCommandLineFlags=" --include .*/${currentDirectory}/${word}/*"
if [ "$vflag" = "on" ]; then
echo
echo -n "Path included in oclint analysis is:$includedCommandLineFlags"
fi
# Run OCLint with the right set of compiler options
runCommand no oclint-json-compilation-database -v $includedCommandLineFlags -- -rc LONG_LINE=$longLineThreshold -max-priority-1 $maxPriority -max-priority-2 $maxPriority -max-priority-3 $maxPriority -report-type pmd -o sonar-reports/$appScheme-oclint.xml
done < tmpFileRunSonarSh
rm -rf tmpFileRunSonarSh
else
echo 'Skipping OCLint (test purposes only!)'
fi
#FauxPas
if [ "$fauxpas" = "on" ] && [ "$hasObjC" = "yes" ]; then
hash fauxpas 2>/dev/null
if [ $? -eq 0 ]; then
echo -n 'Running FauxPas...'
if [ "$projectCount" = "1" ]
then
fauxpas -o json check $projectFile --workspace $workspaceFile --scheme $appScheme > sonar-reports/fauxpas.json
else
echo $projectFile | sed -n 1'p' | tr ',' '\n' > tmpFileRunSonarSh
while read projectName; do
$XCODEBUILD_CMD -list -project $projectName | sed -n '/Schemes/,$p' | while read scheme
do
if [ "$scheme" = "" ]
then
exit
fi
if [ "$scheme" == "${scheme/Schemes/}" ]
then
if [ "$scheme" != "$testScheme" ]
then
projectBaseDir=$(dirname $projectName)
workspaceRelativePath=$(python -c "import os.path; print os.path.relpath('$workspaceFile', '$projectBaseDir')")
fauxpas -o json check $projectName --workspace $workspaceRelativePath --scheme $scheme > sonar-reports/$(basename $projectName .xcodeproj)-$scheme-fauxpas.json
fi
fi
done
done < tmpFileRunSonarSh
rm -rf tmpFileRunSonarSh
fi
else
echo 'Skipping FauxPas (not installed)'
fi
else
echo 'Skipping FauxPas'
fi
# Lizard Complexity
if [ "$lizard" = "on" ]; then
if hash $LIZARD_CMD 2>/dev/null; then
echo -n 'Running Lizard...'
$LIZARD_CMD --xml "$srcDirs" > sonar-reports/lizard-report.xml
else
echo 'Skipping Lizard (not installed!)'
fi
else
echo 'Skipping Lizard (test purposes only!)'
fi
# The project version from properties file
numVersionSonarRunner=''; readParameter numVersionSonarRunner 'sonar.projectVersion'
if [ -z "$numVersionSonarRunner" -o "$numVersionSonarRunner" = " " ]; then
numVersionSonarRunner=" --define sonar.projectVersion=$numVerionFromPlist"
else
#if we have version number in properties file, we don't overide numVersion for sonar-runner/sonar-scanner command
numVersionSonarRunner='';
fi
# SonarQube
if [ "$sonarscanner" = "on" ]; then
echo -n 'Running SonarQube using SonarQube Scanner'
if hash /dev/stdout sonar-scanner 2>/dev/null; then
runCommand /dev/stdout sonar-scanner $numVersionSonarRunner
else
echo 'Skipping sonar-scanner (not installed!)'
fi
else
echo -n 'Running SonarQube using SonarQube Runner'
if hash /dev/stdout sonar-runner 2>/dev/null; then
runCommand /dev/stdout sonar-runner $numVersionSonarRunner
else
runCommand /dev/stdout sonar-scanner $numVersionSonarRunner
fi
fi
# Kill progress indicator
stopProgress
exit 0
Here is the terminal output:
Running run-sonar-swift.sh...
Project count is [1]
2021-09-07 14:48:13.089 defaults[49259:620007]
The domain/default pair of (/Users/ebubekirsezer/Desktop/Projects/SonarDemo/SonarDemo/Info.plist, CFBundleShortVersionString) does not exist
Xcode project file is: SonarDemo.xcodeproj
Xcode workspace file is:
Xcode application scheme is: SonarDemo
Number version from plist is:
Destination simulator is: platform=iOS Simulator,name=iPhone 8,OS=14.5
Excluded paths from coverage are:
Creating directory sonar-reports/
Extracting Xcode project information
+ xcodebuild clean build -project SonarDemo.xcodeproj -scheme SonarDemo -destination 'platform=iOS Simulator,name=iPhone 8,OS=14.5' -destination-timeout 360 COMPILER_INDEX_STORE_ENABLE=NO
+ returnValue=0
+ set +x
./run-sonar-swift.sh: line 291: xcpretty: command not found
stat: compile_commands.json: stat: No such file or directory
actual = , min = 3
./run-sonar-swift.sh: line 299: [: -ge: unary operator expected
Running surefire
+ xcodebuild clean build test -project SonarDemo.xcodeproj -scheme SonarDemo -configuration Debug -enableCodeCoverage YES -destination 'platform=iOS Simulator,name=iPhone 8,OS=14.5' -destination-timeout 60
2021-09-07 14:48:26.363 xcodebuild[49322:621312] [MT] DVTAssertions: Warning in /Library/Caches/com.apple.xbs/Sources/IDEFrameworks/IDEFrameworks-18212/IDEFoundation/Testing/IDETestRunSpecificationBuilder.m:678
Details: Failed to compute path to baseline file during test run spec construction: <XCTHTestRunSpecification: 0x7fced2696a60>
Object: <IDETestRunSpecificationBuilder>
Method: +testRunSpecificationsForTestingSpecifiers:scheme:buildables:withBuildParameters:additionalEnvironmentVariables:additionalCommandLineArguments:testRerunPolicy:includeClangProfileParameters:shouldDebugAppExtensions:error:
Thread: <NSThread: 0x7fcf0241a660>{number = 1, name = main}
Please file a bug at https://feedbackassistant.apple.com with this warning message and any useful information you can provide.
2021-09-07 14:48:26.365 xcodebuild[49322:621312] [MT] DVTAssertions: Warning in /Library/Caches/com.apple.xbs/Sources/IDEFrameworks/IDEFrameworks-18212/IDEFoundation/Testing/IDETestRunSpecificationBuilder.m:678
Details: Failed to compute path to baseline file during test run spec construction: <XCTHTestRunSpecification: 0x7fceb25809f0>
Object: <IDETestRunSpecificationBuilder>
Method: +testRunSpecificationsForTestingSpecifiers:scheme:buildables:withBuildParameters:additionalEnvironmentVariables:additionalCommandLineArguments:testRerunPolicy:includeClangProfileParameters:shouldDebugAppExtensions:error:
Thread: <NSThread: 0x7fcf0241a660>{number = 1, name = main}
Please file a bug at https://feedbackassistant.apple.com with this warning message and any useful information you can provide.
2021-09-07 14:50:17.771 xcodebuild[49322:621312] [MT] IDETestOperationsObserverDebug: 110.166 elapsed -- Testing started completed.
2021-09-07 14:50:17.772 xcodebuild[49322:621312] [MT] IDETestOperationsObserverDebug: 0.000 sec, +0.000 sec -- start
2021-09-07 14:50:17.772 xcodebuild[49322:621312] [MT] IDETestOperationsObserverDebug: 110.166 sec, +110.166 sec -- end
+ returnValue=0
+ set +x
./run-sonar-swift.sh: line 323: xcpretty: command not found
mv: build/reports/junit.xml: No such file or directory
\nComputing coverage report\n
Command line exclusion flags for slather is:
slather coverage --binary-basename SonarDemo --input-format profdata --cobertura-xml --output-directory sonar-reports --scheme SonarDemo SonarDemo.xcodeproj
+ slather coverage --binary-basename SonarDemo --input-format profdata --cobertura-xml --output-directory sonar-reports --scheme SonarDemo SonarDemo.xcodeproj
./run-sonar-swift.sh: line 101: slather: command not found
+ returnValue=127
+ set +x
ERROR - Command 'slather coverage --binary-basename SonarDemo --input-format profdata --cobertura-xml --output-directory sonar-reports --scheme SonarDemo SonarDemo.xcodeproj' failed with error code: 127
Here is my groovy file
timestamps{
node('cf_slave'){
checkout scm
stage('Read the file') {
def PWD = pwd()
withEnv(["prj_option=${params.project}"]) {
def response =sh(returnStdout: true, script: 'sh \'jenkins/security/get_values.sh\'')
}
}
This is my get_values.sh file
echo "The project option is:" $prj_option
prj_name=$(echo "$prj_option" | tr '[:upper:]' '[:lower:]')
file_name="va_input_file_$prj_name.txt"
echo "The project option is:" $file_name
ls -la
chmod 775 jenkins/security/$file_name
ls -la
get_input_values() {
file=$1
IFS=''
while read line
do
if [ `echo ${line} | grep -E -c -w "NAME_SPACE" ` -gt 0 ]; then
NAME_SPACE=$(echo " ${line}" | cut -d'=' -f2)
echo "The name space value is $NAME_SPACE"
elif [ `echo ${line} | grep -E -c -w "IMAGE_NAMES" ` -gt 0 ]; then
values=$(echo " ${line}" | cut -d'=' -f2)
echo "THE DOCKERIMAGES are $DOCKER_IMAGES_NAMES"
else
echo "Please provide input for namespace and docker images to be scanned by VA_TOOl"
fi
done < ${file}
}
images=$(get_input_values ${file_name})
so here my text file is under jenkins/security folder of gitrepo but unfortunately I am getting this error:
16:05:28 + sh jenkins/security/get_values.sh
16:05:28 jenkins/security/get_values.sh: 16: jenkins/security/get_values.sh: cannot open va_input_file_icp.txt: No such file```
Unfortunately, there is a ticket for this in Jenkins (https://issues.jenkins-ci.org/browse/JENKINS-51245) which was closed as a duplicate of this ticket: (https://issues.jenkins-ci.org/browse/JENKINS-27413)
JENKINS-27413 was raised in 2015, and is still open. The File Parameter appears not to work in Jenkins Pipeline. It does however work when used in a Freestyle project. While not ideal, I would recommend changing your job to be a Freestyle project if that's feasible.
I'm trying to run celery as a daemon in the background on Ubuntu 14.04.
I've followed the instructions at http://celery.readthedocs.org/en/latest/tutorials/daemonizing.html and used the celeryd shell script
#!/bin/sh -e
# ============================================
# celeryd - Starts the Celery worker daemon.
# ============================================
#
# :Usage: /etc/init.d/celeryd {start|stop|force-reload|restart|try-restart|status}
# :Configuration file: /etc/default/celeryd
#
# See http://docs.celeryproject.org/en/latest/tutorials/daemonizing.html#generic-init-scripts
### BEGIN INIT INFO
# Provides: celeryd
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: celery task worker daemon
### END INIT INFO
#
#
# To implement separate init scripts, copy this script and give it a different
# name:
# I.e., if my new application, "little-worker" needs an init, I
# should just use:
#
# cp /etc/init.d/celeryd /etc/init.d/little-worker
#
# You can then configure this by manipulating /etc/default/little-worker.
#
VERSION=10.1
echo "celery init v${VERSION}."
if [ $(id -u) -ne 0 ]; then
echo "Error: This program can only be used by the root user."
echo " Unprivileged users must use the 'celery multi' utility, "
echo " or 'celery worker --detach'."
exit 1
fi
# Can be a runlevel symlink (e.g. S02celeryd)
if [ -L "$0" ]; then
SCRIPT_FILE=$(readlink "$0")
else
SCRIPT_FILE="$0"
fi
SCRIPT_NAME="$(basename "$SCRIPT_FILE")"
DEFAULT_USER="celery"
DEFAULT_PID_FILE="/var/run/celery/%n.pid"
DEFAULT_LOG_FILE="/var/log/celery/%n.log"
DEFAULT_LOG_LEVEL="INFO"
DEFAULT_NODES="celery"
DEFAULT_CELERYD="-m celery worker --detach"
CELERY_DEFAULTS=${CELERY_DEFAULTS:-"/etc/default/${SCRIPT_NAME}"}
# Make sure executable configuration script is owned by root
_config_sanity() {
local path="$1"
local owner=$(ls -ld "$path" | awk '{print $3}')
local iwgrp=$(ls -ld "$path" | cut -b 6)
local iwoth=$(ls -ld "$path" | cut -b 9)
if [ "$(id -u $owner)" != "0" ]; then
echo "Error: Config script '$path' must be owned by root!"
echo
echo "Resolution:"
echo "Review the file carefully and make sure it has not been "
echo "modified with mailicious intent. When sure the "
echo "script is safe to execute with superuser privileges "
echo "you can change ownership of the script:"
echo " $ sudo chown root '$path'"
exit 1
fi
if [ "$iwoth" != "-" ]; then # S_IWOTH
echo "Error: Config script '$path' cannot be writable by others!"
echo
echo "Resolution:"
echo "Review the file carefully and make sure it has not been "
echo "modified with malicious intent. When sure the "
echo "script is safe to execute with superuser privileges "
echo "you can change the scripts permissions:"
echo " $ sudo chmod 640 '$path'"
exit 1
fi
if [ "$iwgrp" != "-" ]; then # S_IWGRP
echo "Error: Config script '$path' cannot be writable by group!"
echo
echo "Resolution:"
echo "Review the file carefully and make sure it has not been "
echo "modified with malicious intent. When sure the "
echo "script is safe to execute with superuser privileges "
echo "you can change the scripts permissions:"
echo " $ sudo chmod 640 '$path'"
exit 1
fi
}
if [ -f "$CELERY_DEFAULTS" ]; then
_config_sanity "$CELERY_DEFAULTS"
echo "Using config script: $CELERY_DEFAULTS"
. "$CELERY_DEFAULTS"
fi
# Sets --app argument for CELERY_BIN
CELERY_APP_ARG=""
if [ ! -z "$CELERY_APP" ]; then
CELERY_APP_ARG="--app=$CELERY_APP"
fi
CELERYD_USER=${CELERYD_USER:-$DEFAULT_USER}
# Set CELERY_CREATE_DIRS to always create log/pid dirs.
CELERY_CREATE_DIRS=${CELERY_CREATE_DIRS:-0}
CELERY_CREATE_RUNDIR=$CELERY_CREATE_DIRS
CELERY_CREATE_LOGDIR=$CELERY_CREATE_DIRS
if [ -z "$CELERYD_PID_FILE" ]; then
CELERYD_PID_FILE="$DEFAULT_PID_FILE"
CELERY_CREATE_RUNDIR=1
fi
if [ -z "$CELERYD_LOG_FILE" ]; then
CELERYD_LOG_FILE="$DEFAULT_LOG_FILE"
CELERY_CREATE_LOGDIR=1
fi
CELERYD_LOG_LEVEL=${CELERYD_LOG_LEVEL:-${CELERYD_LOGLEVEL:-$DEFAULT_LOG_LEVEL}}
CELERY_BIN=${CELERY_BIN:-"celery"}
CELERYD_MULTI=${CELERYD_MULTI:-"$CELERY_BIN multi"}
CELERYD_NODES=${CELERYD_NODES:-$DEFAULT_NODES}
export CELERY_LOADER
if [ -n "$2" ]; then
CELERYD_OPTS="$CELERYD_OPTS $2"
fi
CELERYD_LOG_DIR=`dirname $CELERYD_LOG_FILE`
CELERYD_PID_DIR=`dirname $CELERYD_PID_FILE`
# Extra start-stop-daemon options, like user/group.
if [ -n "$CELERYD_CHDIR" ]; then
DAEMON_OPTS="$DAEMON_OPTS --workdir=$CELERYD_CHDIR"
fi
check_dev_null() {
if [ ! -c /dev/null ]; then
echo "/dev/null is not a character device!"
exit 75 # EX_TEMPFAIL
fi
}
maybe_die() {
if [ $? -ne 0 ]; then
echo "Exiting: $* (errno $?)"
exit 77 # EX_NOPERM
fi
}
create_default_dir() {
if [ ! -d "$1" ]; then
echo "- Creating default directory: '$1'"
mkdir -p "$1"
maybe_die "Couldn't create directory $1"
echo "- Changing permissions of '$1' to 02755"
chmod 02755 "$1"
maybe_die "Couldn't change permissions for $1"
if [ -n "$CELERYD_USER" ]; then
echo "- Changing owner of '$1' to '$CELERYD_USER'"
chown "$CELERYD_USER" "$1"
maybe_die "Couldn't change owner of $1"
fi
if [ -n "$CELERYD_GROUP" ]; then
echo "- Changing group of '$1' to '$CELERYD_GROUP'"
chgrp "$CELERYD_GROUP" "$1"
maybe_die "Couldn't change group of $1"
fi
fi
}
check_paths() {
if [ $CELERY_CREATE_LOGDIR -eq 1 ]; then
create_default_dir "$CELERYD_LOG_DIR"
fi
if [ $CELERY_CREATE_RUNDIR -eq 1 ]; then
create_default_dir "$CELERYD_PID_DIR"
fi
}
create_paths() {
create_default_dir "$CELERYD_LOG_DIR"
create_default_dir "$CELERYD_PID_DIR"
}
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
_get_pidfiles () {
# note: multi < 3.1.14 output to stderr, not stdout, hence the redirect.
${CELERYD_MULTI} expand "${CELERYD_PID_FILE}" ${CELERYD_NODES} 2>&1
}
_get_pids() {
found_pids=0
my_exitcode=0
for pidfile in $(_get_pidfiles); do
local pid=`cat "$pidfile"`
local cleaned_pid=`echo "$pid" | sed -e 's/[^0-9]//g'`
if [ -z "$pid" ] || [ "$cleaned_pid" != "$pid" ]; then
echo "bad pid file ($pidfile)"
one_failed=true
my_exitcode=1
else
found_pids=1
echo "$pid"
fi
if [ $found_pids -eq 0 ]; then
echo "${SCRIPT_NAME}: All nodes down"
exit $my_exitcode
fi
done
}
_chuid () {
su "$CELERYD_USER" -c "$CELERYD_MULTI $*"
}
start_workers () {
if [ ! -z "$CELERYD_ULIMIT" ]; then
ulimit $CELERYD_ULIMIT
fi
_chuid $* start $CELERYD_NODES $DAEMON_OPTS \
--pidfile="$CELERYD_PID_FILE" \
--logfile="$CELERYD_LOG_FILE" \
--loglevel="$CELERYD_LOG_LEVEL" \
$CELERY_APP_ARG \
$CELERYD_OPTS
}
dryrun () {
(C_FAKEFORK=1 start_workers --verbose)
}
stop_workers () {
_chuid stopwait $CELERYD_NODES --pidfile="$CELERYD_PID_FILE"
}
restart_workers () {
_chuid restart $CELERYD_NODES $DAEMON_OPTS \
--pidfile="$CELERYD_PID_FILE" \
--logfile="$CELERYD_LOG_FILE" \
--loglevel="$CELERYD_LOG_LEVEL" \
$CELERY_APP_ARG \
$CELERYD_OPTS
}
kill_workers() {
_chuid kill $CELERYD_NODES --pidfile="$CELERYD_PID_FILE"
}
restart_workers_graceful () {
echo "WARNING: Use with caution in production"
echo "The workers will attempt to restart, but they may not be able to."
local worker_pids=
worker_pids=`_get_pids`
[ "$one_failed" ] && exit 1
for worker_pid in $worker_pids; do
local failed=
kill -HUP $worker_pid 2> /dev/null || failed=true
if [ "$failed" ]; then
echo "${SCRIPT_NAME} worker (pid $worker_pid) could not be restarted"
one_failed=true
else
echo "${SCRIPT_NAME} worker (pid $worker_pid) received SIGHUP"
fi
done
[ "$one_failed" ] && exit 1 || exit 0
}
check_status () {
my_exitcode=0
found_pids=0
local one_failed=
for pidfile in $(_get_pidfiles); do
if [ ! -r $pidfile ]; then
echo "${SCRIPT_NAME} down: no pidfiles found"
one_failed=true
break
fi
local node=`basename "$pidfile" .pid`
local pid=`cat "$pidfile"`
local cleaned_pid=`echo "$pid" | sed -e 's/[^0-9]//g'`
if [ -z "$pid" ] || [ "$cleaned_pid" != "$pid" ]; then
echo "bad pid file ($pidfile)"
one_failed=true
else
local failed=
kill -0 $pid 2> /dev/null || failed=true
if [ "$failed" ]; then
echo "${SCRIPT_NAME} (node $node) (pid $pid) is down, but pidfile exists!"
one_failed=true
else
echo "${SCRIPT_NAME} (node $node) (pid $pid) is up..."
fi
fi
done
[ "$one_failed" ] && exit 1 || exit 0
}
case "$1" in
start)
check_dev_null
check_paths
start_workers
;;
stop)
check_dev_null
check_paths
stop_workers
;;
reload|force-reload)
echo "Use restart"
;;
status)
check_status
;;
restart)
check_dev_null
check_paths
restart_workers
;;
graceful)
check_dev_null
restart_workers_graceful
;;
kill)
check_dev_null
kill_workers
;;
dryrun)
check_dev_null
dryrun
;;
try-restart)
check_dev_null
check_paths
restart_workers
;;
create-paths)
check_dev_null
create_paths
;;
check-paths)
check_dev_null
check_paths
;;
*)
echo "Usage: /etc/init.d/${SCRIPT_NAME} {start|stop|restart|graceful|kill|dryrun|create-paths}"
exit 64 # EX_USAGE
;;
esac
exit 0
,
which I put in /etc/init.d/celeryd.
I've also got the following config filw (also called celeryd which lives in etc/default/celeryd
# Names of nodes to start
# most will only start one node:
CELERYD_NODES="worker"
# but you can also start multiple and configure settings
# for each in CELERYD_OPTS (see `celery multi --help` for examples).
# Absolute or relative path to the 'celery' command:
CELERY_BIN="/usr/local/bin/celery"
# App instance to use
# comment out this line if you don't use an app
CELERY_APP="proj"
# or fully qualified:
#CELERY_APP="proj.tasks:app"
# Where to chdir at start.
CELERYD_CHDIR="/home/drmclean/"
# Extra command-line arguments to the worker
CELERYD_OPTS="--time-limit=300 --concurrency=8"
# %N will be replaced with the first part of the nodename.
CELERYD_LOG_FILE="/var/log/celery/%N.log"
CELERYD_PID_FILE="/var/run/celery/%N.pid"
# Workers should run as an unprivileged user.
# You need to create this user manually (or you can choose
# a user/group combination that already exists, e.g. nobody).
CELERYD_USER="drmclean"
CELERYD_GROUP="drmclean"
# If enabled pid and log directories will be created if missing,
# and owned by the userid/group configured.
CELERY_CREATE_DIRS=1
I can easily start the celery service running by using the command:
sudo /etc/init.d/celeryd start
and the service runs as I expect.
However on start-up the service never runs. When I inspect the logfile for the celery, it says.
"[2014-09-17 16:27:41,541: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**#127.0.0.1:5672//: [Errno 111] Connection refused.
Trying again in 2.00 seconds..."
Can anyone help with this error? I can't see when the connection would be refused on start-up but also when using the sudo /etc/init.d/celeryd start command?
Are you connecting from a remote server? If yes, the guest user is not allowed to connect from a remote server. See https://www.rabbitmq.com/access-control.html
No the entire thing is running on my own machine. Actually it appears that my celeryd script which is in:
/etc/init.d/celeryd
is never running or start-up. It's unclear why it isn't though.
I have a script to check the status of a url. I am trying to grep for the word connected from the below mentioned wget command output and print Running if it is found else print Not Running. How can I modify my grep to print only the word without the all the output from wget command
#!/bin/ksh
STAT=`wget 'http://server:port/ABC_Service/app' | grep connected`
if [ -z "$STAT" ] ; then
echo "Running"
else
echo "Not Running"
fi
Output of wget command:
--2013-05-31 11:09:32-- http://server:port/ABC_Service/app
Resolving server... 10.109.136.31
Connecting to server|10.109.136.31|:port... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Authorization failed.
Desired Output from my script:
Running
Check the return code
#!/bin/ksh
#use your wget command in place of echo below
echo "connected" 2>&1 | grep connected >/dev/null
retcode=$?
if [ $retcode = 0 ]
then
echo "Running"
else
echo "Not Running"
fi
If you can use Bash, then the variable $? reads the exit status of the last command executed.