
Error 참고
npm error - code EJSONPARSE
error : error - code EJSONPARSE
해결방안
package.json 의 불필요한 콤마, / ,// 등을 지워주거나 코드를 바꿔줌
스크립트 실행시 에러발생
// 윈도우에서 스크립트 파일을 만들고 linux에서 실행했기때문
// 줄바꿈을 의미하는 기행문자가 달라서 발생하는 문제라고 함
error: /bin/sh^M: bad interpreter : No such file or directory
해결방안
$ vim [filename] //해당파일로 접근하여 " ^M "을 지워줌
branch 이동중 내 branch 정보를 제대로 읽어오지 못하는
push,pull,merge 등 원격 Repo와 통신할 때 에러 발생
error: fatal: Could not read from remote repository.
해결방안
$ git remote - v //원격 저장소 연결 상태 확인
$ git remote remove [원격저장소이름 (master,main ,etc)]
$ git remote add [원격저장소이름 (master,main ,etc)] [github 원격저장소 url]
git pull시
error : cannot open.git/FETCH_HEAD: Permission denied
해결방안
1안
$ sudo chown -R $USER .git/ //난 이결로 해결
2안
$ sudo chmod a+rwx .git/FETCH_HEAD
권한(허가)인증 거부 에러발생
error: ./folder/file : Permission denied
해결방안
$ chmod +x [filename]
git pull 시 에러발생
error: The following untracked working tree files would be overwritten by merge: folder/file
해결 방안
$git clean -d -fx .
$ git add *
$ git stash
$ git add * $ git stash $ git pull origin master/{branch_name}
Jenkins server 에서 node server로 접속시
error : Permission denied (public key)
해결방안
ssh node에서 Jenkins를 향해 ssh ubuntu@ ip주소 로 ssh키를 발급받았었나? 생각이안남... ㅜㅜ
node 서버 에서 ssh key 를 다시 발급받고 github의 ssh키를 새로 만들고 그 키를 node서버
authorized_key 맨 밑에 또 넣어준걸로 기억함... 맞나 이게?

Jenkins Test 시작! 이전에 우선
Test는 AWS EC2 instance 2개를 사용
자신의 code 서버(Node server) 와 code를 Jenkins로 작동시킬 서버(Jenkins server)
즉, 터미널 창 2개로 설정한다 ~ (EC2 ubuntu 20.04 프리티어 사용)
저장소가 public일경우~ private이면 따로 github token을 발급 받아야 한다
참고 블로그 https://kwonyeeun.tistory.com/80
Jenkins server
1. 자바 버전 확인
$ java --version
$ javac --version
없다면 설치
$ sudo apt-get install default-jdk
or
$ sudo apt install default-jre
$ sudo apt install default-jdk
2. Jenkins 설치
$ curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
$ echo 'deb https://pkg.jenkins.io/debian-stable binary/' | sudo tee -a /etc/apt/sources.list.d/jenkins.list
$ cd
$ sudo apt update
$ sudo apt install jenkins
3. Jenkins 시작
$ sudo systemctl start jenkins.service
$ sudo systemctl enable jenkins.service
4. port enable
$ sudo ufw allow 8080
$ sudo ufw allow 22
$ sudo ufw enable
$ sudo ufw status
방화벽 상태확인 (inactive)이면 (active로만듬)
$ suddo ufw enable
EC2 보안 규칙편집
5. 브라우저에서 http://AWS EC2 인스턴스 퍼블릭 IPv4 주소 : 8080/ 으로 접속
6. 아래 명령어로 명령 실행 후 나오는 코드를 위 Administrator password 에 복붙
$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword
7. Install suggested plugins 클릭 후 설치 후 커피한잔~
8. 설치가 완료되면 계정 을 만들고
Jenkins URL : //AWS EC2 publicIP :8080
defalut 로 걍 나둠
여기까지 Jenkins Server 1단계 클리어
vsCode
node app에 코드 추가 (script에 파일 확장자 명은 없음)
./node_modules/.bin/mocha ./test/test.js
테스트 돌려봄
Node Server
1. node 서버에서 ssh key gen 해주기 email은 github 이메일이 네이버라 이렇게씀
$ ssh-keygen -t rsa -C "sinsk23@naver.com"
ls -al , cd, cat 등의 명령어 사용으로 .ssh/id_rsa.pub의 내용을 복사
ssh ~~ .com 까지 전체를 복사한다!
GitHub SSH key
2. 본인의 깃헙 github -> settings(맨오른쪽상단 프로필사진 클릭시) -> SSH and GPG keys -> New SSH key
-> 복붙후 발급되면 OK
3. 내 프로젝트중 Code Clone을 HTTPS 로 해왔다면 이번엔 SSH로 클론할꺼임 클론 주소 코드 복사
Node Server
4. github ssh클론 주소 코드 서버에 넣기
$ git clone git@github.com: 클론 주소 코드.git
Jenkins 브라우저 //AWS EC2 publicIP :8080
1. 아까 접속한 젠킨스 브라우저에서 설정을 해줌
Jenkins 관리 -> 플러그인 관리 -> 설치가능 탭에서 -> nodejs 검색후 -> Download now and install after restart
2. 다시 젠킨스 설정
Jenkins 관리 -> Global tool configuration - > NodeJS 찾아서 Add NodeJS
-> Name 은 Node JS 16.17.0 (자신의 node version 을 씀) -> Install from nodejs.org의 NodeJS Version을 16.17.0으로 바꿔준다 ->save
3. 새로운 Item 구성
Item name 아무거나 입력 -> Freestyle project 클릭 -> 소스코드 관리 -> git 체크 -> Repo URL은 github Repo HTTP clone url
4. 빌드유발 -> GitHub hook trigger for GITScm polling 체크
빌드환경 -> Provide Node & npm bin/ foler to PATH 체크
5. Build !!!!!! Execute shell
./script/test 권한이 없어 Permission denied가... 그래서 chmod +x 권한을 줌
Github webhook
1. 해당 프로젝트(해당 Repo)의 Settings에 들어가 webhooks를 세팅해준다
Payload URL에
http://AWS EC2 publicIP :8080/github-webhook/
중요 webhook뒤에 / 붙여줘야함
content type은 application/x-www-form-urlencoded
Just the push event 체크
Active 체크안되어있으면 체크 후 Add webhook
Jenkins Server
$ sudo su - jenkins
$ ssh-keygen -t rsa
$ cat ~/.ssh/id_rsa.pub
ssh ~ .com 까지 복사
Node Server
$ vim ~/.ssh/authorized_keys
Jenkins server에서 복사해온 키를 붙여넣어준다
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/*
Jenkins Server
Jenkins server에서 node Server로 접속 할때 sudo su - jenkins 로 Jenkins 접속후
$ ssh ubuntu@IP-171-31-44-105
//IP-171-31-44-105는 node Server의 IP임
나중에는 IP 생각이 안났을 때 너무 귀찮아서
$ vi ~/.ssh/config
로 config 파일 생성후 config 파일에 vim으로 설정
이제 vscode에서 직접 깃헙에 푸시하거나 소스트리,git desk 등 을 써서 push 하면

Vscode 에서 push -> github ->webhook->shell 실행( Jenkins -> Jenkins server-> Node server -> githup pull) ->자동배포!
로 알고있음 현재 2022/09/17
Git 참고 블로그
https://ekimnida.tistory.com/11
https://gorokke.tistory.com/22
https://goddaehee.tistory.com/253
https://velog.io/@ha_jni/Git-push-fetch-merge-pull
ubuntu/linux #!/bin/sh 참고 블로그
https://storycompiler.tistory.com/101
Jenkins 참고 블로그
https://honeyinfo7.tistory.com/294
빛과같은 분들 ㅜㅜ 그리고 우혁님 : https://coding-daily.tistory.com/
https://justinadpark.tistory.com/17?category=739024
AWS에서 Jenkins와 Node.js를 이용한 서비스 구성 Part 3: Jenkins - Node.js App Integration
What are we going to build? In this article series, we will build a simple Node.js app that hosted on AWS EC2 instance. Furthermore, we are going to configure automation server and host Jenkins on..
justinadpark.tistory.com
https://choseongho93.tistory.com/298?category=959709
[JenKins] ⑤ 젠킨스를 이용해서 node.js CI/CD 자동 배포하는 방법 (NestJS)
JenKins를 이용해서 node.js 배포하는 방법 (NestJS) 4편에 이어서 5편을 포스팅하겠습니다. ▼ Jenkins를 통해 자동배포 (NodeJS) 시리즈 ▶ ① 젠킨스를 이용해서 node.js CI/CD 자동 배포하는 방법 - 바로가..
choseongho93.tistory.com
'WIL' 카테고리의 다른 글
AWS Elastic Load Balancing 개념정리 (0) | 2022.09.22 |
---|---|
Jenkins, Elastic Beanstalk 연동 (0) | 2022.09.19 |
6주차를 마무리하며... (Swagger) (0) | 2022.08.23 |
http->https로 바꿔주기 (0) | 2022.08.17 |
5주차 마무리하며... (0) | 2022.08.15 |