kubesphere.io/api@v0.0.0-20231107125330-c9a03957060c/devops/v1alpha3/pipeline_types.go (about) 1 /* 2 Copyright 2020 The KubeSphere Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package v1alpha3 18 19 import ( 20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 ) 22 23 // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! 24 // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. 25 26 const PipelineFinalizerName = "pipeline.finalizers.kubesphere.io" 27 28 const ( 29 ResourceKindPipeline = "Pipeline" 30 ResourceSingularPipeline = "pipeline" 31 ResourcePluralPipeline = "pipelines" 32 PipelinePrefix = "pipeline.devops.kubesphere.io/" 33 PipelineSpecHash = PipelinePrefix + "spechash" 34 PipelineSyncStatusAnnoKey = PipelinePrefix + "syncstatus" 35 PipelineSyncTimeAnnoKey = PipelinePrefix + "synctime" 36 PipelineSyncMsgAnnoKey = PipelinePrefix + "syncmsg" 37 ) 38 39 // PipelineSpec defines the desired state of Pipeline 40 type PipelineSpec struct { 41 // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster 42 // Important: Run "make" to regenerate code after modifying this file 43 Type string `json:"type" description:"type of devops pipeline, in scm or no scm"` 44 Pipeline *NoScmPipeline `json:"pipeline,omitempty" description:"no scm pipeline structs"` 45 MultiBranchPipeline *MultiBranchPipeline `json:"multi_branch_pipeline,omitempty" description:"in scm pipeline structs"` 46 } 47 48 // PipelineStatus defines the observed state of Pipeline 49 type PipelineStatus struct { 50 // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster 51 // Important: Run "make" to regenerate code after modifying this file 52 } 53 54 // +genclient 55 // +kubebuilder:object:root=true 56 57 // Pipeline is the Schema for the pipelines API 58 // +k8s:openapi-gen=true 59 type Pipeline struct { 60 metav1.TypeMeta `json:",inline"` 61 metav1.ObjectMeta `json:"metadata,omitempty"` 62 63 Spec PipelineSpec `json:"spec,omitempty"` 64 Status PipelineStatus `json:"status,omitempty"` 65 } 66 67 // +kubebuilder:object:root=true 68 69 // PipelineList contains a list of Pipeline 70 type PipelineList struct { 71 metav1.TypeMeta `json:",inline"` 72 metav1.ListMeta `json:"metadata,omitempty"` 73 Items []Pipeline `json:"items"` 74 } 75 76 func init() { 77 SchemeBuilder.Register(&Pipeline{}, &PipelineList{}) 78 } 79 80 const ( 81 NoScmPipelineType = "pipeline" 82 MultiBranchPipelineType = "multi-branch-pipeline" 83 ) 84 85 const ( 86 SourceTypeSVN = "svn" 87 SourceTypeGit = "git" 88 SourceTypeSingleSVN = "single_svn" 89 SourceTypeGitlab = "gitlab" 90 SourceTypeGithub = "github" 91 SourceTypeBitbucket = "bitbucket_server" 92 ) 93 94 type NoScmPipeline struct { 95 Name string `json:"name" description:"name of pipeline"` 96 Description string `json:"description,omitempty" description:"description of pipeline"` 97 Discarder *DiscarderProperty `json:"discarder,omitempty" description:"Discarder of pipeline, managing when to drop a pipeline"` 98 Parameters []Parameter `json:"parameters,omitempty" description:"Parameters define of pipeline,user could pass param when run pipeline"` 99 DisableConcurrent bool `json:"disable_concurrent,omitempty" mapstructure:"disable_concurrent" description:"Whether to prohibit the pipeline from running in parallel"` 100 TimerTrigger *TimerTrigger `json:"timer_trigger,omitempty" mapstructure:"timer_trigger" description:"Timer to trigger pipeline run"` 101 RemoteTrigger *RemoteTrigger `json:"remote_trigger,omitempty" mapstructure:"remote_trigger" description:"Remote api define to trigger pipeline run"` 102 Jenkinsfile string `json:"jenkinsfile,omitempty" description:"Jenkinsfile's content'"` 103 } 104 105 type MultiBranchPipeline struct { 106 Name string `json:"name" description:"name of pipeline"` 107 Description string `json:"description,omitempty" description:"description of pipeline"` 108 Discarder *DiscarderProperty `json:"discarder,omitempty" description:"Discarder of pipeline, managing when to drop a pipeline"` 109 TimerTrigger *TimerTrigger `json:"timer_trigger,omitempty" mapstructure:"timer_trigger" description:"Timer to trigger pipeline run"` 110 SourceType string `json:"source_type" description:"type of scm, such as github/git/svn"` 111 GitSource *GitSource `json:"git_source,omitempty" description:"git scm define"` 112 GitHubSource *GithubSource `json:"github_source,omitempty" description:"github scm define"` 113 GitlabSource *GitlabSource `json:"gitlab_source,omitempty" description:"gitlab scm define"` 114 SvnSource *SvnSource `json:"svn_source,omitempty" description:"multi branch svn scm define"` 115 SingleSvnSource *SingleSvnSource `json:"single_svn_source,omitempty" description:"single branch svn scm define"` 116 BitbucketServerSource *BitbucketServerSource `json:"bitbucket_server_source,omitempty" description:"bitbucket server scm defile"` 117 ScriptPath string `json:"script_path" mapstructure:"script_path" description:"script path in scm"` 118 MultiBranchJobTrigger *MultiBranchJobTrigger `json:"multibranch_job_trigger,omitempty" mapstructure:"multibranch_job_trigger" description:"Pipeline tasks that need to be triggered when branch creation/deletion"` 119 } 120 121 type GitSource struct { 122 ScmId string `json:"scm_id,omitempty" description:"uid of scm"` 123 Url string `json:"url,omitempty" mapstructure:"url" description:"url of git source"` 124 CredentialId string `json:"credential_id,omitempty" mapstructure:"credential_id" description:"credential id to access git source"` 125 DiscoverBranches bool `json:"discover_branches,omitempty" mapstructure:"discover_branches" description:"Whether to discover a branch"` 126 DiscoverTags bool `json:"discover_tags,omitempty" mapstructure:"discover_tags" description:"Discover tags configuration"` 127 CloneOption *GitCloneOption `json:"git_clone_option,omitempty" mapstructure:"git_clone_option" description:"advavced git clone options"` 128 RegexFilter string `json:"regex_filter,omitempty" mapstructure:"regex_filter" description:"Regex used to match the name of the branch that needs to be run"` 129 } 130 131 // GithubSource and BitbucketServerSource have the same structure, but we don't use one due to crd errors 132 type GithubSource struct { 133 ScmId string `json:"scm_id,omitempty" description:"uid of scm"` 134 Owner string `json:"owner,omitempty" mapstructure:"owner" description:"owner of github repo"` 135 Repo string `json:"repo,omitempty" mapstructure:"repo" description:"repo name of github repo"` 136 CredentialId string `json:"credential_id,omitempty" mapstructure:"credential_id" description:"credential id to access github source"` 137 ApiUri string `json:"api_uri,omitempty" mapstructure:"api_uri" description:"The api url can specify the location of the github apiserver.For private cloud configuration"` 138 DiscoverBranches int `json:"discover_branches,omitempty" mapstructure:"discover_branches" description:"Discover branch configuration"` 139 DiscoverPRFromOrigin int `json:"discover_pr_from_origin,omitempty" mapstructure:"discover_pr_from_origin" description:"Discover origin PR configuration"` 140 DiscoverPRFromForks *DiscoverPRFromForks `json:"discover_pr_from_forks,omitempty" mapstructure:"discover_pr_from_forks" description:"Discover fork PR configuration"` 141 DiscoverTags bool `json:"discover_tags,omitempty" mapstructure:"discover_tags" description:"Discover tag configuration"` 142 CloneOption *GitCloneOption `json:"git_clone_option,omitempty" mapstructure:"git_clone_option" description:"advavced git clone options"` 143 RegexFilter string `json:"regex_filter,omitempty" mapstructure:"regex_filter" description:"Regex used to match the name of the branch that needs to be run"` 144 } 145 146 type GitlabSource struct { 147 ScmId string `json:"scm_id,omitempty" description:"uid of scm"` 148 Owner string `json:"owner,omitempty" mapstructure:"owner" description:"owner of gitlab repo"` 149 Repo string `json:"repo,omitempty" mapstructure:"repo" description:"repo name of gitlab repo"` 150 ServerName string `json:"server_name,omitempty" description:"the name of gitlab server which was configured in jenkins"` 151 CredentialId string `json:"credential_id,omitempty" mapstructure:"credential_id" description:"credential id to access gitlab source"` 152 ApiUri string `json:"api_uri,omitempty" mapstructure:"api_uri" description:"The api url can specify the location of the gitlab apiserver.For private cloud configuration"` 153 DiscoverBranches int `json:"discover_branches,omitempty" mapstructure:"discover_branches" description:"Discover branch configuration"` 154 DiscoverPRFromOrigin int `json:"discover_pr_from_origin,omitempty" mapstructure:"discover_pr_from_origin" description:"Discover origin PR configuration"` 155 DiscoverPRFromForks *DiscoverPRFromForks `json:"discover_pr_from_forks,omitempty" mapstructure:"discover_pr_from_forks" description:"Discover fork PR configuration"` 156 DiscoverTags bool `json:"discover_tags,omitempty" mapstructure:"discover_tags" description:"Discover tags configuration"` 157 CloneOption *GitCloneOption `json:"git_clone_option,omitempty" mapstructure:"git_clone_option" description:"advavced git clone options"` 158 RegexFilter string `json:"regex_filter,omitempty" mapstructure:"regex_filter" description:"Regex used to match the name of the branch that needs to be run"` 159 } 160 161 type BitbucketServerSource struct { 162 ScmId string `json:"scm_id,omitempty" description:"uid of scm"` 163 Owner string `json:"owner,omitempty" mapstructure:"owner" description:"owner of github repo"` 164 Repo string `json:"repo,omitempty" mapstructure:"repo" description:"repo name of github repo"` 165 CredentialId string `json:"credential_id,omitempty" mapstructure:"credential_id" description:"credential id to access github source"` 166 ApiUri string `json:"api_uri,omitempty" mapstructure:"api_uri" description:"The api url can specify the location of the github apiserver.For private cloud configuration"` 167 DiscoverBranches int `json:"discover_branches,omitempty" mapstructure:"discover_branches" description:"Discover branch configuration"` 168 DiscoverPRFromOrigin int `json:"discover_pr_from_origin,omitempty" mapstructure:"discover_pr_from_origin" description:"Discover origin PR configuration"` 169 DiscoverPRFromForks *DiscoverPRFromForks `json:"discover_pr_from_forks,omitempty" mapstructure:"discover_pr_from_forks" description:"Discover fork PR configuration"` 170 DiscoverTags bool `json:"discover_tags,omitempty" mapstructure:"discover_tags" description:"Discover tag configuration"` 171 CloneOption *GitCloneOption `json:"git_clone_option,omitempty" mapstructure:"git_clone_option" description:"advavced git clone options"` 172 RegexFilter string `json:"regex_filter,omitempty" mapstructure:"regex_filter" description:"Regex used to match the name of the branch that needs to be run"` 173 } 174 175 type MultiBranchJobTrigger struct { 176 CreateActionJobsToTrigger string `json:"create_action_job_to_trigger,omitempty" description:"pipeline name to trigger"` 177 DeleteActionJobsToTrigger string `json:"delete_action_job_to_trigger,omitempty" description:"pipeline name to trigger"` 178 } 179 180 type GitCloneOption struct { 181 Shallow bool `json:"shallow,omitempty" mapstructure:"shallow" description:"Whether to use git shallow clone"` 182 Timeout int `json:"timeout,omitempty" mapstructure:"timeout" description:"git clone timeout mins"` 183 Depth int `json:"depth,omitempty" mapstructure:"depth" description:"git clone depth"` 184 } 185 186 type SvnSource struct { 187 ScmId string `json:"scm_id,omitempty" description:"uid of scm"` 188 Remote string `json:"remote,omitempty" description:"remote address url"` 189 CredentialId string `json:"credential_id,omitempty" mapstructure:"credential_id" description:"credential id to access svn source"` 190 Includes string `json:"includes,omitempty" description:"branches to run pipeline"` 191 Excludes string `json:"excludes,omitempty" description:"branches do not run pipeline"` 192 } 193 type SingleSvnSource struct { 194 ScmId string `json:"scm_id,omitempty" description:"uid of scm"` 195 Remote string `json:"remote,omitempty" description:"remote address url"` 196 CredentialId string `json:"credential_id,omitempty" mapstructure:"credential_id" description:"credential id to access svn source"` 197 } 198 199 type DiscoverPRFromForks struct { 200 Strategy int `json:"strategy,omitempty" mapstructure:"strategy" description:"github discover strategy"` 201 Trust int `json:"trust,omitempty" mapstructure:"trust" description:"trust user type"` 202 } 203 204 type DiscarderProperty struct { 205 DaysToKeep string `json:"days_to_keep,omitempty" mapstructure:"days_to_keep" description:"days to keep pipeline"` 206 NumToKeep string `json:"num_to_keep,omitempty" mapstructure:"num_to_keep" description:"nums to keep pipeline"` 207 } 208 209 type Parameter struct { 210 Name string `json:"name" description:"name of param"` 211 DefaultValue string `json:"default_value,omitempty" mapstructure:"default_value" description:"default value of param"` 212 Type string `json:"type" description:"type of param"` 213 Description string `json:"description,omitempty" description:"description of pipeline"` 214 } 215 216 type TimerTrigger struct { 217 // user in no scm job 218 Cron string `json:"cron,omitempty" description:"jenkins cron script"` 219 220 // use in multi-branch job 221 Interval string `json:"interval,omitempty" description:"interval ms"` 222 } 223 224 type RemoteTrigger struct { 225 Token string `json:"token,omitempty" description:"remote trigger token"` 226 } 227 228 func init() { 229 SchemeBuilder.Register(&Pipeline{}, &PipelineList{}) 230 }