Jenkins sudo: not found Build step 'Execute shell' marked build as failure ๊ถŒํ•œ ์—๋Ÿฌ ํ•ด๊ฒฐํ•˜๊ธฐ

2021. 4. 30. 17:10ใ†๐ŸŒฑ Develop/devOps

Jenkins๋กœ docker ์ด๋ฏธ์ง€๋ฅผ ๋นŒ๋“œํ•˜๊ณ  hub์— ํ‘ธ์‹œํ•˜๋Š” ๊ณผ์ •์„ .sh ํŒŒ์ผ ํ•˜๋‚˜๋ฅผ ์‹คํ–‰ํ•ด์„œ ํ•œ๊บผ๋ฒˆ์— ์ˆ˜ํ–‰ํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ Jenkins๊ฐ€ ec2 ์„œ๋ฒ„์—์„œ  sudo ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋ฉด, Jenkins์—๊ฒŒ ๋”ฐ๋กœ ๊ถŒํ•œ์„ ์ค˜์•ผํ•ฉ๋‹ˆ๋‹ค. ๊ถŒํ•œ์„ ์ฃผ์ง€ ์•Š๊ณ  ๋นŒ๋“œํ•˜๋ฉด sudo: not found Build step 'Execute shell' marked build as failure ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋‚ฉ๋‹ˆ๋‹ค.

 

๊ทธ๋ž˜์„œ root ๊ณ„์ •์œผ๋กœ ๋“ค์–ด๊ฐ€์„œ /etc/sudoers ํŒŒ์ผ์„ ์ˆ˜์ •ํ•ด์ค์‹œ๋‹ค.

su # ๋ฃจํŠธ ๊ณ„์ •์œผ๋กœ ์ ‘์†ํ•˜๊ธฐ, password ๋ฅผ ๋ชจ๋ฅธ๋‹ค๋ฉด ์ดˆ๊ธฐ ์„ค์ •ํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. 
cd /etc # etc ํด๋”๋กœ ๋“ค์–ด๊ฐ€์„œ 
vi sudoers # root ๊ถŒํ•œ์œผ๋กœ sudoers ํŒŒ์ผ ์—ด๊ธฐ

sudoers ํŒŒ์ผ๋กœ ๋“ค์–ด๊ฐ€์„œ, jenkins์—๊ฒŒ ๊ถŒํ•œ์„ ์ค๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์  ํ‚จ์Šค์—๊ฒŒ ๋ชจ๋“  ๊ถŒํ•œ์„ ์ฃผ๋Š” ๊ฒƒ์ด ๋ณด์•ˆ ์ƒ์˜ ์ด์œ ๋กœ ๊ฑฑ์ •์ด ๋œ๋‹ค๋ฉด, jenkins๊ฐ€ ์‹คํ–‰ํ•ด์•ผํ•˜๋Š” ํŒŒ์ผ ๊ฒฝ๋กœ๋ฅผ ์ ์–ด์„œ ๊ทธ ํŒŒ์ผ ์‹คํ–‰์—๋งŒ ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 

jenkins ALL=(ALL) NOPASSWD: ALL jenkins ALL=(ALL) NOPASSWD: ํŒŒ์ผ ๊ฒฝ๋กœ....

 

๊ทธ๋Ÿฌ๋ฉด ๋นŒ๋“œ ์‹œ ๋‚ฌ๋˜ ์—๋Ÿฌ๊ฐ€ ์‚ฌ๋ผ์ง€๊ณ  .sh ํŒŒ์ผ์ด ์ž˜ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค!