Jenkins etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Jenkins etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

30 Ekim 2022 Pazar

Jenkins Credentials

Örnek - token
Açıklaması şöyle
Go to Manage Jenkins-> Manage Credentials-> Choose Secret Text type credential and paste the token which is generated in Jfrog Platform and add ID and Description as artifactory-access-token

Örnek - Kullanıcı İsmi ve Şifre
Açıklaması şöyle
To publish an image to your repository you will need to add the credentials of your Docker Hub account to Jenkins, do so by navigating to Manage Jenkins > Manage Credentials > System > Global Credentials > Add Credentials. Add your credentials and give them an id that you will use later.
Şeklen şöyle




29 Ekim 2022 Cumartesi

Jenkins Global Tool Configuration

Giriş
Menü şöyle
Manage Jenkins > Global Tool Configuration
Node.Js ve Docker Kurulum
Açıklaması şöyle
Go back to the dashboard and then to Manage Jenkins > Global Tool Configuration. For both Docker and NodeJS, give it a name and select Install automatically, then select install from nodejs.org and from docker.com. Click Save/Apply.
Node.js şeklen şöyle

Docker şeklen şöyle


7 Ekim 2022 Cuma

Jenkins Ortam Değişlenleri

Giriş
Açıklaması şöyle
$JOB_NAME — The name that you give your job when it is first set up.
$NODE_NAME — This is the name of the node on which the current build is running.
$JENKINS_URL — This is set to the URL of the Jenkins master that is responsible for running the build.
$BUILD_URL — Indicates the URL where the results of the builds can be found.
$WORKSPACE — Refers to the path of the workspace

Jenkins Pluginler

Giriş
Jenkins'e bir sürü plugin kurulabiliyor. Çoğu plugin harici bir komutun çıktısını göstermek üzere tasarlanmış.

Pluginler şurada
Manage Jenkins > Manage Plugins
JDK Tool Plugin
Bunun kurulum Manage Plugins altında değil. Manage Jenkins > Global Tool Configuration altında. Şeklen şöyle. Listede hazır gelen bir JDK sürümü veya bir zip kurması sağlanabilir.



Git Plugin
Açıklaması şöyle
1. Once you are at Jenkins Dashboard click on the “Manage Jenkins” button.
2. Click on Manage Plugins
3. On the Plugin page, select the GIT Plugin.
4. Install the Git plugin and restart your Jenkins.
4. Once you install the plugins, go to Manage Jenkins on your Jenkins dashboard. You will see your plugins listed among the rest.
Docker Plugin
Örnek ver

Docker Pipeline Plugin
Örnek ver

NodeJS Plugin
Örnek ver

SLOCCount Plugin
1. SLOCCount plugin kurulur

2. Execute shell alanına sayma işlemini yapan komut yazılır. Linux'ta kod saymak için iki araç var. Bunlar cloc ve sloc. sloc şöyle kullanılır.
sloccount --wide --details . > sloccount.sc
Aslında bash scriptleri için varsayılan çalışma alanı workspace dizinidir. Ancak emin olamadığım için böyle yazdım.
cloc ${WORKSPACE} --by-file --xml -out=${WORKSPACE}/cloc.xml
3. Publish SLOCLCount Analysis result alanına slockcount.sc veya clock.xml adını ekle.

Eğer cloc komutunu terminalde çalıştırmak isteseydik şöyle yapardık. 1234567 getirmek istediğimiz revizyon numarası olsun.
svn checkout -r 1234567 http:/... mysrc
cloc "mysrc/"


Jenkins Jobs

Giriş
Açıklaması şöyle
Freestyle

Freestyle build jobs are general-purpose build jobs, which provide maximum flexibility. It can be used for any type of project.

Multi-configuration

The multi-configuration project allows users to run the same build job on different environments. It is used for testing an application in different environments.

Folder

This project allows users to create folders to organize and categorize similar jobs in one folder or subfolder.

Multi-branch Pipeline

This project type lets you implement different Jenkinsfiles for different branches of the same project.

Pipeline

This project runs the entire software development workflow as code. Rather than creating several jobs for each stage of software development, you can now run the entire workflow as one code.

GitHub Organisation
This project scans your entire GitHub organization and creates Pipeline jobs for each repository containing a Jenkinsfile.
1. Freestyle
Örnek
Şöyle yaparız


Örnek
Şöyle yaparız
Click New item, give it a name (I called mine “continuous-integration”), and then select Freestyle Project. You will be presented with a bunch of option, the following settings should be set:

- Under Source Code Management, select git, then enter the URL of your GitHub repo as well as the branch you would like Jenkins to listen to.
- Under Build Triggers, select GitHub hook trigger for GITScm polling
- Under Build Environment, select Provide Node & npm bin/ folder to PATH. Select your node installation under NodeJS Installation
- Under Build, add the build step Execute Shell and in the prompt enter:
  npm install
  npm test
Şeklen şöyle


4. Multi-branch pipeline
Açıklaması şöyle
How do you create a multi-branch Jenkins pipeline?
In a Multi-branch Pipeline project, Jenkins automatically discovers, manages, and executes Pipelines for branches that contain a Jenkinsfile in source control.

To create a Multi-branch Jenkins Pipeline

1. Open Jenkins Dashboard and create a new item by clicking “New Item”
2. Enter the project name, and from the options select “Multi-branch pipeline”
3. Once you confirm, select the repository location, and branch source and add the branch source credentials.
4. After saving the project, Jenkins automatically creates new Multibranch Pipelines for repositories
5. Then to connect to the GitHub repo, we need the HookURL
6. To get this URL from the repository settings, add this HookURL to the Webhooks section
7. Once the jobs are created, Jenkins will automatically trigger the build.
Bir video burada. Açıklaması şöyle. Yani aynı pipeline farklı branch'ler için otomatik olarak yaratılıyor ve çalıştırılıyor.
A multi-branch pipeline is a concept of automatically creating Jenkins pipelines based on Git branches. It can automatically discover new branches in the source control (Github) and automatically create a pipeline for that branch. When the pipeline build starts, Jenkins uses the Jenkinsfile in that branch for build stages.

SCM (Source Control) can be Github, Bitbucket, or a Gitlab repo.
Benzer bir açıklama şöyle
Jenkins Pipeline Vs. Multibranch Pipeline
A normal pipeline job is meant for building a single branch from the SCM and deploy to a single environment. 

A multibranch pipeline is meant for building multiple branches from a repository and deploy to multiple environments if required.
5. Pipeline
Docker image deployment için kullanılır
Örnek
Açıklaması şöyle
Now go back to the dashboard and create a new item and select Pipeline.

Under Build Triggers, select Build after other projects are built, enter the name of your previous CI item, and select Trigger only if build is stable. That way we will only deploy the application if the previous tests succeeded.
Şeklen şöyle

Açıklaması şöyle
Next under Pipeline, select Pipeline script and enter the following script. Make sure to change the environment variables at the top of the script. Change registry (repository) and gitUrl/gitBranch to your repositories, and change the registryCredential variable to the id of your Docker Hub credentials that you created earlier.
Şöyle yaparız
pipeline {
    environment {
        registry = 'christophergustafson/node-application'
        registryCredential = 'dockerhub'
        dockerImage = ''
        gitBranch = 'main'
        gitUrl = 'https://github.com/ChristopherGustafson/tutorial-app.git'
    }

    agent any
    stages {
            stage('Cloning our Git') {
                steps {
                    git branch:gitBranch, url:gitUrl
                }
            }

            stage('Building Docker Image') {
                steps {
                    script {
                        dockerImage = docker.build registry + ":$BUILD_NUMBER"
                    }
                }
            }

            stage('Deploying Docker Image to Dockerhub') {
                steps {
                    script {
                        docker.withRegistry('', registryCredential) {
                        dockerImage.push()
                        }
                    }
                }
            }

            stage('Cleaning Up') {
                steps{
                  sh "docker rmi --force $registry:$BUILD_NUMBER"
                }
            }
        }
    }




Jenkins jenkins.exe

Giriş
Kullanım şöyle
# Start Jenkins
jenkins.exe start

# Stop Jenkins
jenkins.exe stop

# Restart Jenkins
jenkins.exe restart
stop seçeneği
Servisi durdurmak için şöyle yaparız.
jenkins.exe stop

21 Eylül 2022 Çarşamba

Jenkins Manage Nodes - Master ve Slave

Giriş
Master ve Agent arasında bağlantı için 3 yöntem var
1. SSH Connector
2. Inbound Connector
3. Custom Script

1. Master'ın public key Agent üzerindeki "/home/jenkins/.ssh/authorized_keys" dosyasına kopyalanır. authorized_keys Dosyası yazısına bakabilirsiniz
2. Master'dan Agent'a ssh komutuyla yani elle bir ssh bağlantısı açılır
3. Bu bağlantının neticesinde güncellenen known_hosts dosyasını tekrar Jenkins'e kopyalanır
sudo cp ~/.ssh/known_hosts /var/lib/jenkins/.ssh
known_hosts Dosyası yazısına bakabilirsiniz
4. Master Jenkins'e yeni bağlantı için private key ekrandan girilir

Örnek
1. Soldaki Manage Jenkins menüsüne tıklanır
2. Manage Nodes and Clouds düğmesine tıklanır
3. Sol tarafta New Node menüsüne tıklanır
4. Node ismi girilir, ayrıca " Permanent agent" seçeneği de seçilir
Ekrandaki bazı alanların açıklaması şöyle
Name : Enter the name of slave node

Description : Enter the detailed description of the slave node

Number of Executor: This means that no. of jobs in the slave machine can run parallelly based on the count is given in the text box. Here is given as 1 (it can be change based on the user specification for execution), 

Label: Enter the label name of the slave machine.

Usage: In this field, two options are available ,one is "Use this node as much as possibl"e and another one is "Only build jobs with label expressions matching this node". Here is selected as option1 (Use this node as much as possible)

Launch Method : Select the option "Launch agent by connecting it to the controller(Master)

Custom WorkDir path :Enter the slave workspace directory(path) in this field.

Internal data Directory : Here is used “remoting” as value. And Choose the Use WebSocket option.

In Availability : Select the option as “Keep this agent online as much as possible” and Click on “Save” button.

Jenkins node'larını yönetmek için şöyle yaparız
Yeni node eklemek için şöyle yaparız. Burada "Permanent Agent" seçiliyor

SSH ile bağlanacağımız için şöyle yaparız







15 Eylül 2022 Perşembe

Jenkins Kurulum

Sadece War Dosyası
Jenkins'i indirdikten sonra eğer war dosyasını elle çalıştırmak istersek şöyle yaparız.
java -jar jenkins.war
Proxy tanımlamak istersek şöyle yaparız.
java -DJENKINS_HOME="C:\.jenkins" -Dhudson.model.DirectoryBrowserSupport.CSP
="`script-src 'unsafe-inline';`" -Dhttp.proxyHost=localhost -Dhttp.proxyPort=312
8 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128 -jar %JENKINS_HOME%\jenkins
.war

Tomcat
Kurulum için  war dosyası şuraya kopyalanır
$TOMCAT_HOME/web-app/jenkins.war
Şu adrese gideriz.
http://localhost:8080/jenkins
Docker
Örnek
Şöyle yaparız
docker  network create jenkins

docker run \
--name myjenkins \
--rm \
--detach \
-p 8088:8080 -p 50000:50000 \
-v ~/project/Jenkins_Test/CD-CD-deployment/volume/:/var/jenkins_home \
jenkins/jenkins:lts
İlk şifre şurada
cat Jenkins_Test/CD-CD-deployment/volume/secrets/initialAdminPassword

Ubuntu
Örnek
Şöyle yaparız
How to setup Jenkins on Ubuntu:

1. This is the Debian package repository of Jenkins to automate installation and upgrade. To use this repository, first add the key to your system.

curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
2. Then add a Jenkins apt repository entry:

echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
3. Update your local package index, then finally install Jenkins:

sudo apt-get update
sudo apt-get install fontconfig openjdk-11-jre
sudo apt-get install jenkins

4. Verify:

jenkins --version
veya şöyle yaparız
$ systemctl status Jenkins
Kurduktan sonra localhost:8080 adresine gidersek karşımıza şu ekran çıkar

İlk şifre şurada
$ cat /var/lib/jenkins/secrets/initialAdminPassword


19 Ağustos 2022 Cuma

Jenkins Execute Shell Kutusu

Komut çalışınca çıktısı şuna benzer
Started by user anonymous
Building in workspace ...
...
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Ortam Değişkeni
Build Script yazarken ortam değişkenini atamak gerekebilir. Bu durumda Windows'ta aşağıdaki gibi yaparız.
set MYVAR= abc

Diğer Kabul Dosyalarını Çağırmak
Build Script yazarken başka bat veya sh dosyalarını çağırmak gerekebilir. Çağırılan dosya normalde başka bir kabukta çalışır. Eğer aynı kabukta çalışsın istiyorsak (Execute Windows Batch Script penceresi) Windows'ta call komutu kullanılır. Örnek:
call myfile.bat

Linux'ta ise source edilerek çağırılır.
. Foo.sh 
veya
source Foo.sh
Visual Studio C++
Bat dosyasında Visual Studio Projelerini derlemek için şöyle yaparız:
msbuild /p:Configuration=Release BigProject.sln
Docker
Örnek
Önce Docker'a giriş yapmak gerekir. Şöyle yaparız
# login with docker first.
docker login -u "USERNAME" -p "PASSWORD" docker.io

sudo cp -r $HOME/.docker /var/lib/jenkins/.docker
sudo chown -R jenkins:jenkins /var/lib/jenkins/.docker
sudo usermod -aG docker jenkins # current user must have a group call docker.
Şöyle yaparız. Burada kullanılan değişkenler için Jenkins Ortam Değişlenleri yazısına bakabilirsiniz
username="deletify" # replace your username
v_tag=$JOB_NAME:$GIT_COMMIT # tag for version
l_tag=$JOB_NAME:latest # tag for latest

# build a tag locally
docker build -t $v_tag .

# make tag ready to push to docker registry.
docker tag $v_tag $username/$v_tag
docker tag $v_tag $username/$l_tag

# push both tags to docker registry.
docker push $username/$v_tag
docker push $username/$l_tag

# remove both tags on cicd machine,
# because we don't need them anymore
docker rmi $v_tag $username/$v_tag $username/$l_tag



2 Kasım 2017 Perşembe

Jenkins

Jenkins İş Akışı
Jenkins ve diğer tüm CI sistemleri şu adımları izlerler
  • Poll repository for changes
  • Pull from repository
  • Install dependencies
  • Run tests
  • Stage
  • Deploy
Bu adımlara Deployment Pipeline denir.

Configure System
Jenkins'e kurulan tüm plugin ve sistem ayarları Jenkins > Manage Jenkins > Configure System sayfasından yapılır.

Jenkins Servisi
jenkins.exe yazısına bakabilirsiniz

Jenkins Linux veya Windows'ta servis olarak çalışabilir. Windows'ta servis olarak kurunca şu adrese gideriz.
http://localhost:8080
Linux'ta servisi kontrol etmek için /etc/init.d/jenkins restart gibi bir komut yazılabilir. jenkins.xml'e şöyle yaparız.
<executable>java</executable>
<arguments>-DJENKINS_HOME="C:\.jenkins"
-Dhudson.model.DirectoryBrowserSupport.CSP="`script-src 'unsafe-inline';`"
-Dhttp.proxyHost=localhost
-Dhttp.proxyPort=3128
-Dhttps.proxyHost=localhost
-Dhttps.proxyPort=3128
-jar "%JENKINS_HOME%\jenkins.war"
</arguments>

Login
Açıklaması şöyle
To authenticate a user, there are basically 3 ways.

1. By default, Jenkins store the user data & their credentials in its internal database.
2. Or you can configure Jenkins to use an authentication mechanism, defined by the application server.
3. You can also configure Jenkins to authenticate against the LDAP server.
Internal Database 
Sisteme login için Jenkins'in kendi kullanıcı veri tabanını kullanmak isteyebiliriz. Bu durumda "kullanıcı yaratılsın" seçeneğini etkin yapmak iyi bir fikir. Gerekli kullanıcılar oluşturulduktan sonra bu seçenek kapatılabilir.

Ya da People/Users  menüsünden kullanıcı tanımlamak gerekir. Tomcat ile kullanıyorsak şöyle yaparız.
<?xml version='1.0' encoding='utf-8'?>
  <user username="tomcat" password="tomcat" roles="manager-gui,admin-gui"/>
  <role rolename="admin"/>
  <user username="jenkins-admin" password="secret" roles="admin"/>
</tomcat-users>
Control Center
Kontrol Merkezi altında tüm projeler var. Tüm projelerin yapılandırmak durumunu (Build Status) buradan görülebilir. Build Executor Status yapılandırılmakta olan projeleri, Build Queue ise sırada yapılandırılmayı bekleyen projeleri gösterir.

Eğer master/slave ilişkisi varsa Build Executor Status altında slave makineler de görülür.


Pluginler
Jenkins Pluginler yazısına taşıdım

"Tag This Build"
Yapılandırılan proje gösterilen SVN revizyon numarası ile belirtilen URL'ye kopyalanır. URL'yi SVN'de "Create Folder" menüsü kullanarak oluşturmak gerekebilir.
jenkins-tagBuild-v1.424.works.png - Latest 26/Oct/11 10:09 PM - mike stone