Tuesday, February 1, 2022

Day2 - Jenkins

Jenkins - review - Class Notes

Lab: Create a jenkins server
- Create job
- execute job
- Check log
- Create a node and add to the server
- Webhooks

Install http server java
https://stackoverflow.com/questions/3732109/simple-http-server-in-java-using-only-java-se-api

=======================
Recap
- Maven
- Job
- Jenkins
  - Jekins jobs
    - Config )restrict this project can run
    - URL 
    - Where job is executed
    - Added new agent (node01)
    - Manage jenkins (manage nodes and clouds)
      - nodes - configure - add node and add host with credential (private key)
    - job execute
    - click on job
    - play around

init scripts
--------------------
item name; test pipeline
Strategy: log rotation
15 days
pipeline
pipeline script
hello world
script:
pipeline {
  agent ..
}

copy this code and go to vscode
and search jenkins and paste the code.
if you want to have miltiple stages, you can paste for n number of time and change stage hello1, hello2 and so on.
You can copy this code to jenkins and save.
Click on build now to execute the code.
You can also select jenkins + Maven.

jobname/pipeline syntax-> 
How to trigger jenkins job automatically.
How to access nexus repo?

click on job
- configuration
- build trigger
review the options
build periodically - its like cron job. batch type job. specify the schedule..
- trigger builds remotely (eg, from scripts)
  end point URL
jenkins_url/job/core-app-pipeline/build?token=sdfsdafsdfasf
http://ip:8080/job/core-app-pipeline/build?token=sdfsdafsdfasf
note: only login user can perform the build job
so you have to use the credentials.
- you can't use password but can use token.
click on API TOken
add new token / generate
http://user:token@job/core-app-pipeline/build?token=sdfsdafsdfasf
go to jenkins
- settings
web hooks
 add
payload URL
what time you want to trigger, review the options 
click on add webhook
job is automatically trigger.
=========================
launch new instance
- free tier
- t2.medium
- configure - add storage , security group port 8080, 80 ..
name this instance as nexus
go to security group and add a port
cutom tcp 8081 anywhere, 0.0.0.0/0

go to instnaces and click on nexus. verify its on running state. 
- connect - copy key 
how to create nexus repository
------------------------------
jar file generated will be uploaded to repo.
two approach
- normal approach
- docker hub
install docker package
$ apt install docker
$ apt update
$ docker

search nexus
sonatype nexus docker ..
$ docker run -d -p 8081:8081 --name nexus sonatype/nexus3
you can also use jenkins.
$ docker ps
$ copy nexus public ip address:8081
you got nexus repo
login: admin
pw: get from below command output. 
$ docker exec -it nexus cat /nexus-data/admin.password

it will promt you for new pw, 
- click next - finish

now, we have to upload our artifacts. 
- click on repository
- you can create or use existing repo
- click on repository
you have lots of options available. select based on your request.
maven has 3 type.
proxy - proxy to your repo. 
maven2 type
name: core-snapshots # backup option
layout policy : strict
blobstore(store): 
hosted: deployment ..
..
create repo

maven2
name: core-releases
other option not allowed..
disable redeploy
click on repo and you can copy.
Now, you can go back to your git and change the corporate repository.
<id> maven </id>

you can also take a snapshot version


=================== 
on nexus
Security
- proviledge
- roles
- users
- annonymous accesss
- LDAP
- Realms
- SSL certs

Roles -: role id: core-deployment-role
name: core-deployent-role
role description: core deployment
create role
and create users - create local user
- core user
email: test@best.com
passwod: status: active
done..
to upload aotumatically, use anonymous access...
setting.xml
maven 
github.com/devopsgsc/core-app/tree/dev
today
dynamic agent
webhook
nexus
- setup -> docker
- repo
- perissions
- settings.xml


54.177.243.80:8081
today




No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...