Basic Jenkins

using agent

managing node

stackoverflow

cloudbees

credential

secret text和token看起来没什么差别
gitlab下载code的时候如果使用git协议,那么需要用到ssh类型的credential。
如果使用https协议,不需要用credential。
credential会发送给agent去使用,所以不需要在agent上面做任何配置。
但是有的时候有证书的问题,需要到agent上面去安装target git网站的证书。
ssh类型的credential是,你随便在某个机器上生成公钥和私钥,然后把公钥配置到gitlab,把私钥配置成jenkins的credential。
# git credential setting
git config --global http.sslCAPath /etc/pki/ca-trust/source/anchors/

freestyle

可以设置hook,会提示你hook url,格式是https://$junkins_url/project/$project_name/在jenkins上生成secret text,然后在git里面设置jenkins的hook url和secret text。
需要自己设置build step,不支持jenkinsfile(我没找到如何在freestyle的project里面使用jenkinsfile的方法)
可以设置SCM(Source Code Management)
可以设置UMB
可以设置ENV Parameters email。。。

pipeline

与freestyle的区别是,可以自己在project中定义pipeline

Multibrach Pipeline

每个branch会自动生成一个job
可以自动在git里面创建hook(需要在配置gitlab server的时候开启hook功能,然后创建multibranch pipeline的时候会自动把hook配置到gitlab上面)

Organization

可以为gitlab某个group下的所有repo自动生成Multibrach Pipeline

UMB

需要使用唯一的topic id
会自动生成一些parameter,比如name,version,id,release。。。

Topic: 
  Consumer.kernel-qe.ccc76c29-d5b1-42ea-a1e8-a4f734edb238.VirtualTopic.eng.cki.ready_for_test
  Consumer.kernel-qe.146b83ac-99f9-45a9-a9e9-c2912ab42d7b.VirtualTopic.eng.brew.>

message check: 
  $.artifact.component ^kernel$
  $.merge_request.merge_request_url .*merge_requests.*
  $.merge_request.is_draft false
  $.cki_finished true

JMS selector: 
  (name = 'kernel' AND type = 'Tag' AND (tag LIKE 'RHEL-6._-test' OR tag LIKE 'RHEL-6-test' OR tag LIKE 'rhel-7._-test' OR tag LIKE 'rhel-8%-candidate' OR tag LIKE 'rhel-9%-candidate')) OR (name = 'kernel-alt' AND type = 'Tag' AND (tag LIKE 'rhel-alt-7._-candidate'))

Testing-Farm

require plugins:
  webhook step plugin
  http request plugin

把Testing Farm API Key设置为secret text类型的credential
在Dashboard > Administration > Configures system section添加global library https://github.com/fedora-ci/jenkins-pipeline-library
https://docs.testing-farm.io/Testing%20Farm/0.1/integrations.html#_jenkins

pipeline {
    libraries {
        lib("fedora-pipeline-library@rh-stable")
    }
    agent any
    environment {
        TESTING_FARM_API_KEY = credentials('testing-farm-api-key')
        FEDORA_CI_TESTING_FARM_API_URL = "https://api.dev.testing-farm.io"
        FEDORA_CI_TESTING_FARM_ARTIFACTS_URL = "http://artifacts.dev.testing-farm.io"
    }
    stages {
        stage("Run tests") {
            steps {
                script {
                    hook = registerWebhook()
                    def requestPayload = [
                        api_key: env.TESTING_FARM_API_KEY,
                        test: [
                            fmf: [
                                url: "https://gitlab.cee.redhat.com/liali/tmt-test.git",
                                ref: "main",
                                path: ".",
                                name: "/beaker/beakerlib/plan"
                            ]
                        ],
                        environments: [
                            [
                                arch: "x86_64",
                                os: [
                                    compose: "RHEL-9.2.0-Nightly"
                                ]
                            ]
                        ],
                        notification: [
                            webhook: [
                                url: hook.getURL()
                            ]
                        ]
                    ]
                    def initial_response = submitTestingFarmRequest(payloadMap: requestPayload)
                    tftRequestId = initial_response['id']
                }
            }
        }
        stage('Wait for Testing Farm results') {
            steps {
                script {
                    def job_response = waitForTestingFarm(requestId: tftRequestId, hook: hook)
                    echo "Testing Farm response obtained!"
                    echo "${job_response.apiResponse}"
                }
            }
        }
    }
}

Testing Farm use yourself system

在机器beaker access policy里面添加jenkins/baseos-jenkins.rhev-ci-vms.eng.rdu2.redhat.com
但是这样别人也能用你的机器,最好设置一个pool,通过Jira提ticket.

Testing-farm api-key: 404-bb0bfb78-f4c9-8888-42cf-83f6-58764ef393e0-lia

Declarative && Scripted Pipeline

Declarative Pipeline更简洁,优先使用
Scripted Pipeline功能能丰富。

Questions

case里面如何指定依赖关系 for tmt test
如何提交多机测试,并且为不同的机器分别指定参数