C:\Windows\System32\drivers\etc\hosts 에서 local DNS를 설정할 수 있다.
localhost name resolution is handled within local DNS itself.아래에
ubuntu 사설IP주소와 사용할 domain name을 작성한다.
172.??.??.? jenkins.local
putty에서도 접속할 때 사설IP주소대신 설정한 domain name을 통해 ubuntu서버에 접속가능
docker exec -ti jenkins bash
date 명령어
current date and time
변수 선언하고 사용할 수 있습니다.
명령어는 $(date) 변수는 $NAME 괄호없이
NAME = yoon
echo "hello $NAME Current date and time is $(date)"
echo "hi $(whoami)"
">"는 리디렉션 마크, 오른쪽에 경로를 적으면 그 파일이 생성되면서 output이 그 안에 들어감
echo "hello $NAME Current date and time is $(date)" > /tmp/info
/tmp/info file이 생성되고 그 안에 output이 담깁니다.
jenkins UI 에서 job을 생성하고 그 안에서 Execute Shell 에서 저 명령어 실행시
jenkins container를 실행한 ubuntu 서버의 컨테이너 안에 /tmp/info 파일이 생성되고 ouput이 들어갑니다
use docker to host service, all of the file we created, saved in container
exit을 하고 /tmp/info하면 파일이 없다. 컨테이너 내부에 있기 때문
docker를 실행하면서 생성된 파일을 host에서 볼 수 없습니다 보려면 volumes를 통해 봐야합니다.
vi script.sh
첫줄은 사용할 interpreter를 나타낸다
#!/bin/bash
NAME=$1
LASTNAME=$2
echo "$NAME $LASTNAME hi"
./script.sh 하면 permission error , executable permission 주기위해
chmod +x ./script.sh
./script.sh choi yoon 하면 변수값 들어감
변수 값을 실행하면서 주고 싶을 때 script file에서 parameter 제공받기 위해
NAME=$1 ( 첫 파라미터)
LASTNAME=$2 ( 두 번째 파라미터)
container밖에서 생성했기 때문에 지금 상태에선 container에서 배시 스크립트 실행 못하지만 volumes와 컨테이너 데이터 공유하는 법 배우면 가능합니다.
일단 파일을 컨테이너 안에 복사
docker cp script.sh(file) jenkins(container name):/tmp/script.sh(파일까지의 full path)
컨테이너 내부에서 스크립트 실행하기위해
/tmp/script.sh Choi jy
jenkins UI에서 가능
NAME=C
LASTNAME=JY = 사이에 띄어쓰기하면 빌드 에러
/tmp/script.sh $NAME $LASTNAME
jenkins configuration 에서 this project is parameterized ㅁ -> string parameter ->name default set -> build -> build with parameter로 변경됨
변수 선언하고 사용한 것 처럼 스크립트 실행 가능,
명령어 실행시 파라미터 이름을 같이 전달해줘야함. 1,2파라미터가 아닌 이름으로 매칭된다.
/tmp/script.sh $NAME $LASTNAME
choice paramters
JG
JY
#!/bin/bash
NAME=$1
LASTNAME=$2
SHOW=$3
if [ "$SHOW" = "true" ]; then
echo "Hello, $NAME $LASTNAME"
else
echo "If you want to see the name, please choose mark the show option"
fi
jenkins는 bash실행할 때 쓰일 parameter를 script 파일에 넣어주고
script실행결과를 출력해준다.