Repository: kubesphere/ks-devops
Pull request #785 (2022-08-16 08:01:48)

[release-3.3] Fix the Jenkins cron expression check error
This is an automated cherry-pick of #784

```release-note
None
```

ks-ci-bot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by:
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **linuxsuren** after the PR has been reviewed.
You can assign the PR to them by writing `/assign @linuxsuren` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubesphere%2Fks-devops).

<details open>
Needs approval from an approver in each of these files:

- **[pkg/client/devops/OWNERS](https://github.com/kubesphere/ks-devops/blob/release-3.3/pkg/client/devops/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["linuxsuren"]} -->
ks-ci-bot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubesphere/ks-devops/pull/785#pullrequestreview-1073665849" title="Approved">LinuxSuRen</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubesphere%2Fks-devops).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[pkg/client/devops/OWNERS](https://github.com/kubesphere/ks-devops/blob/release-3.3/pkg/client/devops/OWNERS)~~ [LinuxSuRen]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
LinuxSuRen: /lgtm

Patch:
diff --git a/pkg/client/devops/jenkins/pipeline.go b/pkg/client/devops/jenkins/pipeline.go
index 5c3d3e1..a1935cd 100644
--- a/pkg/client/devops/jenkins/pipeline.go
+++ b/pkg/client/devops/jenkins/pipeline.go
@@ -824,7 +824,8 @@ func interanlErrorMessage() *devops.CheckCronRes {
 }
 
 func parseCronJobTime(msg string) (string, string, error) {
-
+	msg = strings.ReplaceAll(msg, "Coordinated Universal Time", "UTC")
+	msg = strings.ReplaceAll(msg, " at ", " ")
 	times := strings.Split(msg, ";")
 
 	lastTmp := strings.Split(times[0], " ")


Test patch:
diff --git a/pkg/client/devops/jenkins/devops_test.go b/pkg/client/devops/jenkins/devops_test.go
index 48ba4b4..ef05b6c 100644
--- a/pkg/client/devops/jenkins/devops_test.go
+++ b/pkg/client/devops/jenkins/devops_test.go
@@ -30,12 +30,28 @@ func Test_parseCronJobTime(t *testing.T) {
 		Input    string
 		Expected Except
 	}{
-		{"上次运行的时间 Tuesday, September 10, 2019 8:59:09 AM UTC; 下次运行的时间 Tuesday, September 10, 2019 9:14:09 AM UTC.", Except{Last: "2019-09-10T08:59:09Z", Next: "2019-09-10T09:14:09Z"}},
-		{"上次运行的时间 Thursday, January 3, 2019 11:56:30 PM UTC; 下次运行的时间 Friday, January 3, 2020 12:11:30 AM UTC.", Except{Last: "2019-01-03T23:56:30Z", Next: "2020-01-03T00:11:30Z"}},
-		{"上次运行的时间 Tuesday, September 10, 2019 8:41:34 AM UTC; 下次运行的时间 Tuesday, September 10, 2019 9:41:34 AM UTC.", Except{Last: "2019-09-10T08:41:34Z", Next: "2019-09-10T09:41:34Z"}},
-		{"上次运行的时间 Tuesday, September 10, 2019 9:15:26 AM UTC; 下次运行的时间 Tuesday, September 10, 2019 10:03:26 AM UTC.", Except{Last: "2019-09-10T09:15:26Z", Next: "2019-09-10T10:03:26Z"}},
-		{"Would last have run at Tuesday, September 10, 2019 9:15:26 AM UTC; would next run at Tuesday, September 10, 2019 10:03:26 AM UTC.", Except{Last: "2019-09-10T09:15:26Z", Next: "2019-09-10T10:03:26Z"}},
-		{"Would last have run at Tuesday, September 10, 2019 8:41:34 AM UTC; would next run at Tuesday, September 10, 2019 9:41:34 AM UTC.", Except{Last: "2019-09-10T08:41:34Z", Next: "2019-09-10T09:41:34Z"}},
+		{
+			Input:    "上次运行的时间 Tuesday, September 10, 2019 8:59:09 AM UTC; 下次运行的时间 Tuesday, September 10, 2019 9:14:09 AM UTC.",
+			Expected: Except{Last: "2019-09-10T08:59:09Z", Next: "2019-09-10T09:14:09Z"}},
+		{
+			Input:    "上次运行的时间 Thursday, January 3, 2019 11:56:30 PM UTC; 下次运行的时间 Friday, January 3, 2020 12:11:30 AM UTC.",
+			Expected: Except{Last: "2019-01-03T23:56:30Z", Next: "2020-01-03T00:11:30Z"}},
+		{
+			Input:    "上次运行的时间 Tuesday, September 10, 2019 8:41:34 AM UTC; 下次运行的时间 Tuesday, September 10, 2019 9:41:34 AM UTC.",
+			Expected: Except{Last: "2019-09-10T08:41:34Z", Next: "2019-09-10T09:41:34Z"}},
+		{
+			Input:    "上次运行的时间 Tuesday, September 10, 2019 9:15:26 AM UTC; 下次运行的时间 Tuesday, September 10, 2019 10:03:26 AM UTC.",
+			Expected: Except{Last: "2019-09-10T09:15:26Z", Next: "2019-09-10T10:03:26Z"}},
+		{
+			Input:    "上次运行的时间 Tuesday, August 16, 2022 at 12:09:37 AM Coordinated Universal Time; 下次运行的时间 Wednesday, August 17, 2022 at 12:09:37 AM Coordinated Universal Time.",
+			Expected: Except{Last: "2022-08-16T00:09:37Z", Next: "2022-08-17T00:09:37Z"}},
+		{
+			Input:    "Would last have run at Tuesday, September 10, 2019 9:15:26 AM UTC; would next run at Tuesday, September 10, 2019 10:03:26 AM UTC.",
+			Expected: Except{Last: "2019-09-10T09:15:26Z", Next: "2019-09-10T10:03:26Z"}},
+		{
+			Input:    "Would last have run at Tuesday, September 10, 2019 8:41:34 AM UTC; would next run at Tuesday, September 10, 2019 9:41:34 AM UTC.",
+			Expected: Except{Last: "2019-09-10T08:41:34Z", Next: "2019-09-10T09:41:34Z"},
+		},
 	}
 
 	for _, item := range Items {
@@ -51,6 +67,5 @@ func Test_parseCronJobTime(t *testing.T) {
 		if next != item.Expected.Next {
 			t.Errorf("got %#v, expected %#v", next, item.Expected.Next)
 		}
-
 	}
 }