Merge pull request #3125 from LinuxSuRen/discover-tag-support

Add support discover tags for multi-branch pipeline
This commit is contained in:
KubeSphere CI Bot
2020-11-24 11:35:36 +08:00
committed by GitHub
7 changed files with 554 additions and 82 deletions

View File

@@ -108,10 +108,12 @@ type GitSource struct {
Url string `json:"url,omitempty" mapstructure:"url" description:"url of git source"`
CredentialId string `json:"credential_id,omitempty" mapstructure:"credential_id" description:"credential id to access git source"`
DiscoverBranches bool `json:"discover_branches,omitempty" mapstructure:"discover_branches" description:"Whether to discover a branch"`
DiscoverTags bool `json:"discover_tags,omitempty" mapstructure:"discover_tags" description:"Discover tags configuration"`
CloneOption *GitCloneOption `json:"git_clone_option,omitempty" mapstructure:"git_clone_option" description:"advavced git clone options"`
RegexFilter string `json:"regex_filter,omitempty" mapstructure:"regex_filter" description:"Regex used to match the name of the branch that needs to be run"`
}
// GithubSource and BitbucketServerSource have the same structure, but we don't use one due to crd errors
type GithubSource struct {
ScmId string `json:"scm_id,omitempty" description:"uid of scm"`
Owner string `json:"owner,omitempty" mapstructure:"owner" description:"owner of github repo"`
@@ -121,15 +123,11 @@ type GithubSource struct {
DiscoverBranches int `json:"discover_branches,omitempty" mapstructure:"discover_branches" description:"Discover branch configuration"`
DiscoverPRFromOrigin int `json:"discover_pr_from_origin,omitempty" mapstructure:"discover_pr_from_origin" description:"Discover origin PR configuration"`
DiscoverPRFromForks *DiscoverPRFromForks `json:"discover_pr_from_forks,omitempty" mapstructure:"discover_pr_from_forks" description:"Discover fork PR configuration"`
DiscoverTags bool `json:"discover_tags,omitempty" mapstructure:"discover_tags" description:"Discover tag configuration"`
CloneOption *GitCloneOption `json:"git_clone_option,omitempty" mapstructure:"git_clone_option" description:"advavced git clone options"`
RegexFilter string `json:"regex_filter,omitempty" mapstructure:"regex_filter" description:"Regex used to match the name of the branch that needs to be run"`
}
type MultiBranchJobTrigger struct {
CreateActionJobsToTrigger string `json:"create_action_job_to_trigger,omitempty" description:"pipeline name to trigger"`
DeleteActionJobsToTrigger string `json:"delete_action_job_to_trigger,omitempty" description:"pipeline name to trigger"`
}
type BitbucketServerSource struct {
ScmId string `json:"scm_id,omitempty" description:"uid of scm"`
Owner string `json:"owner,omitempty" mapstructure:"owner" description:"owner of github repo"`
@@ -139,10 +137,16 @@ type BitbucketServerSource struct {
DiscoverBranches int `json:"discover_branches,omitempty" mapstructure:"discover_branches" description:"Discover branch configuration"`
DiscoverPRFromOrigin int `json:"discover_pr_from_origin,omitempty" mapstructure:"discover_pr_from_origin" description:"Discover origin PR configuration"`
DiscoverPRFromForks *DiscoverPRFromForks `json:"discover_pr_from_forks,omitempty" mapstructure:"discover_pr_from_forks" description:"Discover fork PR configuration"`
DiscoverTags bool `json:"discover_tags,omitempty" mapstructure:"discover_tags" description:"Discover tag configuration"`
CloneOption *GitCloneOption `json:"git_clone_option,omitempty" mapstructure:"git_clone_option" description:"advavced git clone options"`
RegexFilter string `json:"regex_filter,omitempty" mapstructure:"regex_filter" description:"Regex used to match the name of the branch that needs to be run"`
}
type MultiBranchJobTrigger struct {
CreateActionJobsToTrigger string `json:"create_action_job_to_trigger,omitempty" description:"pipeline name to trigger"`
DeleteActionJobsToTrigger string `json:"delete_action_job_to_trigger,omitempty" description:"pipeline name to trigger"`
}
type GitCloneOption struct {
Shallow bool `json:"shallow,omitempty" mapstructure:"shallow" description:"Whether to use git shallow clone"`
Timeout int `json:"timeout,omitempty" mapstructure:"timeout" description:"git clone timeout mins"`

View File

@@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by deepcopy-gen. DO NOT EDIT.
// Code generated by controller-gen. DO NOT EDIT.
package v1alpha3
@@ -37,7 +37,6 @@ func (in *BitbucketServerSource) DeepCopyInto(out *BitbucketServerSource) {
*out = new(GitCloneOption)
**out = **in
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BitbucketServerSource.
@@ -57,7 +56,6 @@ func (in *DevOpsProject) DeepCopyInto(out *DevOpsProject) {
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
out.Spec = in.Spec
out.Status = in.Status
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DevOpsProject.
@@ -90,7 +88,6 @@ func (in *DevOpsProjectList) DeepCopyInto(out *DevOpsProjectList) {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DevOpsProjectList.
@@ -114,7 +111,6 @@ func (in *DevOpsProjectList) DeepCopyObject() runtime.Object {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DevOpsProjectSpec) DeepCopyInto(out *DevOpsProjectSpec) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DevOpsProjectSpec.
@@ -130,7 +126,6 @@ func (in *DevOpsProjectSpec) DeepCopy() *DevOpsProjectSpec {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DevOpsProjectStatus) DeepCopyInto(out *DevOpsProjectStatus) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DevOpsProjectStatus.
@@ -146,7 +141,6 @@ func (in *DevOpsProjectStatus) DeepCopy() *DevOpsProjectStatus {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DiscarderProperty) DeepCopyInto(out *DiscarderProperty) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DiscarderProperty.
@@ -162,7 +156,6 @@ func (in *DiscarderProperty) DeepCopy() *DiscarderProperty {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DiscoverPRFromForks) DeepCopyInto(out *DiscoverPRFromForks) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DiscoverPRFromForks.
@@ -178,7 +171,6 @@ func (in *DiscoverPRFromForks) DeepCopy() *DiscoverPRFromForks {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *GitCloneOption) DeepCopyInto(out *GitCloneOption) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitCloneOption.
@@ -199,7 +191,6 @@ func (in *GitSource) DeepCopyInto(out *GitSource) {
*out = new(GitCloneOption)
**out = **in
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitSource.
@@ -225,7 +216,6 @@ func (in *GithubSource) DeepCopyInto(out *GithubSource) {
*out = new(GitCloneOption)
**out = **in
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GithubSource.
@@ -241,7 +231,6 @@ func (in *GithubSource) DeepCopy() *GithubSource {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *MultiBranchJobTrigger) DeepCopyInto(out *MultiBranchJobTrigger) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MultiBranchJobTrigger.
@@ -297,7 +286,6 @@ func (in *MultiBranchPipeline) DeepCopyInto(out *MultiBranchPipeline) {
*out = new(MultiBranchJobTrigger)
**out = **in
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MultiBranchPipeline.
@@ -333,7 +321,6 @@ func (in *NoScmPipeline) DeepCopyInto(out *NoScmPipeline) {
*out = new(RemoteTrigger)
**out = **in
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NoScmPipeline.
@@ -349,7 +336,6 @@ func (in *NoScmPipeline) DeepCopy() *NoScmPipeline {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Parameter) DeepCopyInto(out *Parameter) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Parameter.
@@ -369,7 +355,6 @@ func (in *Pipeline) DeepCopyInto(out *Pipeline) {
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
out.Status = in.Status
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Pipeline.
@@ -402,7 +387,6 @@ func (in *PipelineList) DeepCopyInto(out *PipelineList) {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PipelineList.
@@ -436,7 +420,6 @@ func (in *PipelineSpec) DeepCopyInto(out *PipelineSpec) {
*out = new(MultiBranchPipeline)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PipelineSpec.
@@ -452,7 +435,6 @@ func (in *PipelineSpec) DeepCopy() *PipelineSpec {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *PipelineStatus) DeepCopyInto(out *PipelineStatus) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PipelineStatus.
@@ -468,7 +450,6 @@ func (in *PipelineStatus) DeepCopy() *PipelineStatus {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *RemoteTrigger) DeepCopyInto(out *RemoteTrigger) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RemoteTrigger.
@@ -484,7 +465,6 @@ func (in *RemoteTrigger) DeepCopy() *RemoteTrigger {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *SingleSvnSource) DeepCopyInto(out *SingleSvnSource) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SingleSvnSource.
@@ -500,7 +480,6 @@ func (in *SingleSvnSource) DeepCopy() *SingleSvnSource {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *SvnSource) DeepCopyInto(out *SvnSource) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SvnSource.
@@ -516,7 +495,6 @@ func (in *SvnSource) DeepCopy() *SvnSource {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *TimerTrigger) DeepCopyInto(out *TimerTrigger) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TimerTrigger.

View File

@@ -239,6 +239,8 @@ func (c *Controller) syncHandler(key string) error {
klog.V(8).Info(err, fmt.Sprintf("failed to update pipeline config %s ", key))
return err
}
} else {
klog.V(8).Info(fmt.Sprintf("nothing was changed, pipeline '%v'", copyPipeline.Spec))
}
} else {
_, err := c.devopsClient.CreateProjectPipeline(nsName, copyPipeline)

View File

@@ -262,6 +262,9 @@ func appendGitSourceToEtree(source *etree.Element, gitSource *devopsv1alpha3.Git
if gitSource.DiscoverBranches {
traits.CreateElement("jenkins.plugins.git.traits.BranchDiscoveryTrait")
}
if gitSource.DiscoverTags {
traits.CreateElement("jenkins.plugins.git.traits.TagDiscoveryTrait")
}
if gitSource.CloneOption != nil {
cloneExtension := traits.CreateElement("jenkins.plugins.git.traits.CloneOptionTrait").CreateElement("extension")
cloneExtension.CreateAttr("class", "hudson.plugins.git.extensions.impl.CloneOption")
@@ -304,6 +307,10 @@ func getGitSourcefromEtree(source *etree.Element) *devopsv1alpha3.GitSource {
"jenkins.plugins.git.traits.BranchDiscoveryTrait"); branchDiscoverTrait != nil {
gitSource.DiscoverBranches = true
}
if tagDiscoverTrait := traits.SelectElement(
"jenkins.plugins.git.traits.TagDiscoveryTrait"); tagDiscoverTrait != nil {
gitSource.DiscoverTags = true
}
if cloneTrait := traits.SelectElement(
"jenkins.plugins.git.traits.CloneOptionTrait"); cloneTrait != nil {
if cloneExtension := cloneTrait.SelectElement(
@@ -349,6 +356,10 @@ func getGithubSourcefromEtree(source *etree.Element) *devopsv1alpha3.GithubSourc
strategyId, _ := strconv.Atoi(branchDiscoverTrait.SelectElement("strategyId").Text())
githubSource.DiscoverBranches = strategyId
}
if tagDiscoverTrait := traits.SelectElement(
"org.jenkinsci.plugins.github__branch__source.TagDiscoveryTrait"); tagDiscoverTrait != nil {
githubSource.DiscoverTags = true
}
if originPRDiscoverTrait := traits.SelectElement(
"org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait"); originPRDiscoverTrait != nil {
strategyId, _ := strconv.Atoi(originPRDiscoverTrait.SelectElement("strategyId").Text())
@@ -444,6 +455,9 @@ func appendGithubSourceToEtree(source *etree.Element, githubSource *devopsv1alph
}
forkTrait.CreateElement("trust").CreateAttr("class", trustClass)
}
if githubSource.DiscoverTags {
traits.CreateElement("org.jenkinsci.plugins.github__branch__source.TagDiscoveryTrait")
}
if githubSource.CloneOption != nil {
cloneExtension := traits.CreateElement("jenkins.plugins.git.traits.CloneOptionTrait").CreateElement("extension")
cloneExtension.CreateAttr("class", "hudson.plugins.git.extensions.impl.CloneOption")
@@ -491,6 +505,10 @@ func getBitbucketServerSourceFromEtree(source *etree.Element) *devopsv1alpha3.Bi
strategyId, _ := strconv.Atoi(branchDiscoverTrait.SelectElement("strategyId").Text())
s.DiscoverBranches = strategyId
}
if tagDiscoverTrait := traits.SelectElement(
"com.cloudbees.jenkins.plugins.bitbucket.TagDiscoveryTrait"); tagDiscoverTrait != nil {
s.DiscoverTags = true
}
if originPRDiscoverTrait := traits.SelectElement(
"com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait"); originPRDiscoverTrait != nil {
strategyId, _ := strconv.Atoi(originPRDiscoverTrait.SelectElement("strategyId").Text())
@@ -579,6 +597,9 @@ func appendBitbucketServerSourceToEtree(source *etree.Element, s *devopsv1alpha3
}
forkTrait.CreateElement("trust").CreateAttr("class", trustClass)
}
if s.DiscoverTags {
traits.CreateElement("com.cloudbees.jenkins.plugins.bitbucket.TagDiscoveryTrait")
}
if s.CloneOption != nil {
cloneExtension := traits.CreateElement("jenkins.plugins.git.traits.CloneOptionTrait").CreateElement("extension")
cloneExtension.CreateAttr("class", "hudson.plugins.git.extensions.impl.CloneOption")