I'm running the following make target in a buildkite step
cover:
go test ./... -coverprofile=coverage.out
ccover=$$(go tool cover -func cover.out | grep total | grep -Eo '[0-9]+\.[0-9]+');
if [ $$(bc <<< "$$ccover < 20.0") -eq 1 ]; then\
exit 1;\
fi
This is what my buildkite yaml looks like
- label: ":coverage: check code coverage"
key: "cvg"
command:
- make cover
Now when this executes on the server I get the following error
/bin/sh: syntax error: unexpected redirection
make: *** [Makefile:20: analysecover] Error 2
Error: The command exited with status 1
Any idea on what could be going wrong here ?
Related
I'm tyring to exclude test files in my makefile shell command.
When i run the following makefile target,
api-run:
${API_COMPOSE} sh -c "go run -mod=vendor cmd/serverd/*.go"
I get this error
go: cannot run *_test.go files (cmd/serverd/router_test.go)
make: *** [api-run] Error 1
I've tried adjusting the command into
api-run:
${API_COMPOSE} sh -c "for file in \$(ls cmd/serverd/*.go | grep -v _test.go); do go run -mod=vendor \$file; done"
but end up getting this error
sh: 1: Syntax error: "done" unexpected (expecting "do")
make: *** [api-run] Error 2
I have this Makefile that work well:
$ cat Makefile
PMD := ~/pmd-bin-6.31.0/bin/run.sh pmd
gen_quality_analysis:
$(PMD) -d MyCode/ -R rulesets/java/quickstart.xml -f text > quality_analysis/report.txt
$
My problem is that I get an Error 4 from Makefile
$ LANG=en make gen_quality_analysis
~/pmd-bin-6.31.0/bin/run.sh pmd -d AtlasPOC2/ -R rulesets/java/quickstart.xml -f text > quality_analysis/report.txt
Feb 14, 2021 9:53:35 AM net.sourceforge.pmd.PMD encourageToUseIncrementalAnalysis
WARNING: This analysis could be faster, please consider using Incremental Analysis: https://pmd.github.io/pmd-6.31.0/pmd_userdocs_incremental_analysis.html
make: *** [Makefile:15: gen_quality_analysis] Error 4
$
How can I get ride of this
make: *** [Makefile:15: gen_quality_analysis] Error 4
line ?
Note: despite of the fact I get this error 4 the job work well an I get the expected report.txt
In order of preference:
Fix the program ~/pmd-bin-6.31.0/bin/run.sh pmd to return 0 on success.
Write a wrapper that changes the exit status from 4 to 0:
$(PMD) -d ...;\
status=$$?;\
[ $$status -eq 4 ] && status=0;\
exit $$status
Ignore errors for that target with .IGNORE: gen_quality_analysis.
Ignore all errors by running make with make -i.
From the help documentation of pmd - the return code is 4 when violations are found, and this is expected.
https://pmd.github.io/latest/pmd_userdocs_cli_reference.html
Add '-failOnViolation false' if you'd like the return code to be 0 even if violations are found.
I am attempting build a unity project with Xcode and I have a file CrashHunterScript.sh that consists of this:
if [ "$CONFIGURATION" == "Release" ]
then
exit 0
fi
UPLOADER_PATH=$(find $PROJECT_DIR/.. -type f -iname dSYMUploader | sort | uniq | head -n 1)
echo ${UPLOADER_PATH}
if [ -e ${UPLOADER_PATH} ]
then
${UPLOADER_PATH} ${BUILT_PRODUCTS_DIR} ${INFOPLIST_PATH} ${PRODUCT_BUNDLE_IDENTIFIER}
fi
Then this is what Xcode is telling me, with the last 4 lines being the error:
export XCODE_PRODUCT_BUILD_VERSION=10B61
export XCODE_VERSION_ACTUAL=1010
export XCODE_VERSION_MAJOR=1000
export XCODE_VERSION_MINOR=1010
export XPCSERVICES_FOLDER_PATH=appTest.app/XPCServices
export YACC=yacc
export arch=undefined_arch
export variant=normal
/bin/sh -c /Users/me/Library/Developer/Xcode/DerivedData/Unity-iPhone-faweajoqridawgcwcslethajilfw/Build/Intermediates.noindex/Unity-iPhone.build/Debug-iphoneos/Unity-iPhone.build/Script-4252488AB701AFBAC2FB7A9F.sh
/Users/me/UnityProjects/appTest/Builds/appTestBuild/CrashHunterScript.sh: line 2:
: command not found
/Users/me/UnityProjects/appTest/Builds/appTestBuild/CrashHunterScript.sh: line 15: syntax error: unexpected end of file
Command PhaseScriptExecution failed with a nonzero exit code
I am no expert with shell scripts but I did a bit of searching around and can't tell where the syntax error is. Any ideas?
I am trying to write a docker file which will run a RUN command to search for a word in a package.json file and act upon it:
this is my simple dockerfile:
FROM ubuntu:14.04
COPY package.json package.json
RUN if grep -q "grunt" package.json; then echo succeed fi
as you can see i just want a simple if statement but it get this error:
Step 2 : RUN if grep -q "grunt" package.json; then echo succeed fi
---> Running in af460df45239
/bin/sh: 1: Syntax error: end of file unexpected (expecting "fi")
INFO[0001] The command [/bin/sh -c if grep -q "grunt" package.json; then echo succeed fi] returned a non-zero code: 2
How should i run my command?
thanks.
Just like when typing at the shell, you need either a newline or a semicolon before fi:
RUN if grep -q "grunt" package.json; then echo succeed; fi
add this ^
How could I fail build with sane message/status while running Command line build step?
Or course I can exit 1 in my script but I'll get ugly 'Exit code 1' as a build result.
function fail_build {
echo "##teamcity[buildProblem description='$1']" 1>&2
exit 0
}
could be used in script like
cd ./logs
if grep -Pqr 'error text regex' *;
then fail_build "There are errors in logs"; fi
More on TC documentation page.