我正在基于詹金斯(Jenkins(的管道创建此新作业。我希望我的jenkinsfile在bitbucket reposiotry上:假设我的配置文件在 bitbucket.org/config.git
工作任务是清洁安装项目bitbucket.org/myProject.git
我如何配置管道,因此如果在bitbucket.org/myProject.git
中进行任何推动并遵循bitbucket.org/config.git
中定义的步骤?
我不想创建多个分支管道,我不希望我的jenkins文件在同一存储库上,而不是我的项目来编译。
我当前的配置是:
pipeline {
agent any
parameters {
string(defaultValue: '', description: 'URL', name: 'GIT_URL')
string(defaultValue: '', description: 'Credential', name: 'CREDENTIAL_ID')
}
stages {
stage ('Initialize') {
steps {
git branch: 'develop', credentialsId: "${params.CREDENTIAL_ID}", url: "${params.GIT_URL}"
}
}
stage ('Build') {
steps {
sh 'mvn clean install '
echo 'build'
}
}
}
您可以在詹金斯(Jenkins(中使用共享库。您仍然需要代码中的Jenkinsfile,但这不包含任何逻辑。它只会引用共享库并传递任何参数,例如git repo路径。
有关共享库的更多信息,请参阅此链接https://jenkins.io/doc/book/pipeline/pipeline/shared-libraries/。
为了触发构建,您可以在管道中定义扳机。示例:
triggers {
pollSCM('H/5 * * * *')
}
或使用Webhooks(如果您不想进行轮询(。
实际上,我设法使它起作用。在我的詹金斯管道中,我激活了"将更改推向bitbucket时的构建"。
node {
checkout([$class: 'GitSCM',
branches: [[name: 'feature/test-b']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'SubmoduleOption', disableSubmodules: false,
parentCredentials: false, recursiveSubmodules: true, reference: '',
trackingSubmodules: false]], submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'admin',
url: 'http://localhost:7990/scm/bout/boutique-a.git']]])
}
在分支"功能/test-b"中的精品a中进行更改时,我的作业会触发,这很酷。
现在我有一个其他问题,当在> feature/*中进行更改时,我该如何触发当我不在乘坐多支管