| 104 | } |
| 105 | } |
| 106 | func (p Jenkins) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]interface{}) (interface{}, errors.Error) { |
| 107 | // Firstly, let's decode options to JenkinsOptions |
| 108 | op, err := tasks.DecodeTaskOptions(options) |
| 109 | if err != nil { |
| 110 | return nil, err |
| 111 | } |
| 112 | |
| 113 | logger := taskCtx.GetLogger() |
| 114 | logger.Debug("%v", options) |
| 115 | connection := &models.JenkinsConnection{} |
| 116 | connectionHelper := helper.NewConnectionHelper( |
| 117 | taskCtx, |
| 118 | nil, |
| 119 | p.Name(), |
| 120 | ) |
| 121 | if err != nil { |
| 122 | return nil, err |
| 123 | } |
| 124 | err = connectionHelper.FirstById(connection, op.ConnectionId) |
| 125 | if err != nil { |
| 126 | return nil, err |
| 127 | } |
| 128 | |
| 129 | apiClient, err := tasks.CreateApiClient(taskCtx, connection) |
| 130 | if err != nil { |
| 131 | return nil, err |
| 132 | } |
| 133 | |
| 134 | op.ConnectionEndpoint = connection.Endpoint |
| 135 | |
| 136 | err = EnrichOptions(taskCtx, op, apiClient) |
| 137 | if err != nil { |
| 138 | return nil, err |
| 139 | } |
| 140 | |
| 141 | regexEnricher := helper.NewRegexEnricher() |
| 142 | if err := regexEnricher.TryAdd(devops.DEPLOYMENT, op.ScopeConfig.DeploymentPattern); err != nil { |
| 143 | return nil, errors.BadInput.Wrap(err, "invalid value for `deploymentPattern`") |
| 144 | } |
| 145 | if err := regexEnricher.TryAdd(devops.PRODUCTION, op.ScopeConfig.ProductionPattern); err != nil { |
| 146 | return nil, errors.BadInput.Wrap(err, "invalid value for `productionPattern`") |
| 147 | } |
| 148 | taskData := &tasks.JenkinsTaskData{ |
| 149 | Options: op, |
| 150 | ApiClient: apiClient, |
| 151 | Connection: connection, |
| 152 | RegexEnricher: regexEnricher, |
| 153 | } |
| 154 | |
| 155 | return taskData, nil |
| 156 | } |
| 157 | |
| 158 | func (p Jenkins) RootPkgPath() string { |
| 159 | return "github.com/apache/incubator-devlake/plugins/jenkins" |