I want to prevent new programmers pushing code containing console.log
to Bitbucket using pipelines. How I'll do it?
Asked
Active
Viewed 430 times
0
![](../../users/profiles/1000551.webp)
Vadim Kotov
- 7,103
- 8
- 44
- 57
![](../../users/profiles/233286.webp)
ilhan
- 7,981
- 30
- 107
- 186
-
1why would you want that? woudn't it be better to prevent them from being deployed to production? If you use grunt you could use [grunt-remove-logging](https://www.npmjs.com/package/grunt-remove-logging) to remove them. console.log might be useful for debugging local. – Paweł Łukasik Dec 13 '16 at 10:24
-
I've already told them. They use it for debugging but the repository is a production repository. We don't use Node.js. – ilhan Dec 13 '16 at 11:28
-
@olibiaz, it is not a file. It is JavaScript function: https://developer.mozilla.org/en-US/docs/Web/API/Console/log – ilhan Dec 14 '16 at 06:38
1 Answers
0
Assuming that it is not too important to prevent the push, but that it’s enough to make sure that the build fails if console.log()
encountered, you could implement a script step which greps the codebase. I’m doing something like this myself with Bb Pipelines, both with console.log
and debugger
.
The basic approach for that looks something like this:
foundfiles=$(fgrep -rli "console.log" --include='*.js' $BITBUCKET_CLONE_DIR/path/to/files)
result="$?"
if [ "$result" = "0" ]
then
echo "Found in $foundfiles"
exit 1
fi
A Bash script including code such as the above could then be run by your pipeline and will fail if console.log
is found.
![](../../users/profiles/4715679.webp)
BlueM
- 3,157
- 16
- 30