This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new bf13094d fix(jenkins): modify jenkins blueprints
bf13094d is described below
commit bf13094d41a8a5d71a7675276ef803f68e14e646
Author: Yingchu Chen <[email protected]>
AuthorDate: Thu Oct 13 19:51:58 2022 +0800
fix(jenkins): modify jenkins blueprints
---
plugins/jenkins/api/blueprint.go | 18 ++++++-
plugins/jenkins/api/blueprint_test.go | 95 +++++++++++++++++++++++++++++++++++
plugins/jenkins/tasks/task_data.go | 2 +-
3 files changed, 112 insertions(+), 3 deletions(-)
diff --git a/plugins/jenkins/api/blueprint.go b/plugins/jenkins/api/blueprint.go
index bfbdd52e..55b7e5b3 100644
--- a/plugins/jenkins/api/blueprint.go
+++ b/plugins/jenkins/api/blueprint.go
@@ -19,6 +19,7 @@ package api
import (
"encoding/json"
+ "github.com/apache/incubator-devlake/plugins/jenkins/models"
"github.com/apache/incubator-devlake/errors"
"github.com/apache/incubator-devlake/plugins/core"
@@ -27,6 +28,20 @@ import (
)
func MakePipelinePlan(subtaskMetas []core.SubTaskMeta, connectionId uint64,
scope []*core.BlueprintScopeV100) (core.PipelinePlan, errors.Error) {
+ var err errors.Error
+ connection := new(models.JenkinsConnection)
+ err = connectionHelper.FirstById(connection, connectionId)
+ if err != nil {
+ return nil, err
+ }
+ plan, err := makePipelinePlan(subtaskMetas, scope, nil, connection)
+ if err != nil {
+ return nil, err
+ }
+ return plan, nil
+}
+
+func makePipelinePlan(subtaskMetas []core.SubTaskMeta, scope
[]*core.BlueprintScopeV100, apiClient helper.ApiClientGetter, connection
*models.JenkinsConnection) (core.PipelinePlan, errors.Error) {
var err errors.Error
plan := make(core.PipelinePlan, len(scope))
for i, scopeElem := range scope {
@@ -43,7 +58,7 @@ func MakePipelinePlan(subtaskMetas []core.SubTaskMeta,
connectionId uint64, scop
if err != nil {
return nil, err
}
- taskOptions["connectionId"] = connectionId
+ taskOptions["connectionId"] = connection.ID
taskOptions["transformationRules"] = transformationRules
_, err := tasks.DecodeAndValidateTaskOptions(taskOptions)
if err != nil {
@@ -77,7 +92,6 @@ func MakePipelinePlan(subtaskMetas []core.SubTaskMeta,
connectionId uint64, scop
return nil, err
}
doraOption := make(map[string]interface{})
- doraOption["tasks"] = []string{"EnrichTaskEnv"}
doraOption["prefix"] = "jenkins"
doraRules := make(map[string]interface{})
doraRules["productionPattern"] = productionPattern
diff --git a/plugins/jenkins/api/blueprint_test.go
b/plugins/jenkins/api/blueprint_test.go
new file mode 100644
index 00000000..b509709a
--- /dev/null
+++ b/plugins/jenkins/api/blueprint_test.go
@@ -0,0 +1,95 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package api
+
+import (
+ "encoding/json"
+ "github.com/apache/incubator-devlake/models/common"
+ "github.com/apache/incubator-devlake/plugins/core"
+ "github.com/apache/incubator-devlake/plugins/helper"
+ "github.com/apache/incubator-devlake/plugins/jenkins/models"
+ "github.com/stretchr/testify/assert"
+ "testing"
+)
+
+func TestProcessScope(t *testing.T) {
+ connection := &models.JenkinsConnection{
+ RestConnection: helper.RestConnection{
+ BaseConnection: helper.BaseConnection{
+ Name: "jenkins-test",
+ Model: common.Model{
+ ID: 1,
+ },
+ },
+ Endpoint: "https://api.github.com/",
+ Proxy: "",
+ RateLimitPerHour: 0,
+ },
+ BasicAuth: helper.BasicAuth{
+ Username: "Username",
+ Password: "Password",
+ },
+ }
+ //mockMeta := mocks.NewPluginMeta(t)
+
//mockMeta.On("RootPkgPath").Return("github.com/apache/incubator-devlake/plugins/jenkins")
+ //err := core.RegisterPlugin("jenkins", mockMeta)
+ //assert.Nil(t, err)
+ bs := &core.BlueprintScopeV100{
+ Entities: []string{"CICD"},
+ Options: json.RawMessage(`{
+ "jobName": "testJob"
+ }`),
+ Transformation: json.RawMessage(`{
+ "productionPattern": "(?i)build-and-deploy",
+ "deploymentPattern": "deploy"
+ }`),
+ }
+ scopes := make([]*core.BlueprintScopeV100, 0)
+ scopes = append(scopes, bs)
+ plan, err := makePipelinePlan(nil, scopes, nil, connection)
+ assert.Nil(t, err)
+
+ expectPlan := core.PipelinePlan{
+ core.PipelineStage{
+ {
+ Plugin: "jenkins",
+ Subtasks: []string{},
+ Options: map[string]interface{}{
+ "jobName": "testJob",
+ "connectionId": uint64(1),
+ "transformationRules":
map[string]interface{}{
+ "deploymentPattern": "deploy",
+ },
+ },
+ },
+ },
+ core.PipelineStage{
+ {
+ Plugin: "dora",
+ Subtasks: []string{"EnrichTaskEnv"},
+ Options: map[string]interface{}{
+ "prefix": "jenkins",
+ "transformationRules":
map[string]interface{}{
+ "productionPattern":
"(?i)build-and-deploy",
+ },
+ },
+ },
+ },
+ }
+ assert.Equal(t, expectPlan, plan)
+}
diff --git a/plugins/jenkins/tasks/task_data.go
b/plugins/jenkins/tasks/task_data.go
index 0fa4a298..39c3dfd3 100644
--- a/plugins/jenkins/tasks/task_data.go
+++ b/plugins/jenkins/tasks/task_data.go
@@ -32,7 +32,7 @@ type JenkinsApiParams struct {
type JenkinsOptions struct {
ConnectionId uint64 `json:"connectionId"`
- JobName string `json:"JobName"`
+ JobName string `json:"jobName"`
Since string
Tasks []string `json:"tasks,omitempty"`
models.TransformationRules `mapstructure:"transformationRules"
json:"transformationRules"`