diff --git a/src/test/groovy/GetCurrentBuildTimeStepTests.groovy b/src/test/groovy/GetCurrentBuildTimeStepTests.groovy new file mode 100644 index 000000000..3d9b338f2 --- /dev/null +++ b/src/test/groovy/GetCurrentBuildTimeStepTests.groovy @@ -0,0 +1,47 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. 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. + +import org.junit.Before +import org.junit.Test +import static org.junit.Assert.assertTrue + +class GetCurrentBuildTimeStepTests extends ApmBasePipelineTest { + + class BuildMock { + def getTimestampString2(){ return 'date' } + } + + class ClassMock { + BuildMock getRawBuild(){ return new BuildMock() } + } + + @Override + @Before + void setUp() throws Exception { + super.setUp() + script = loadScript('vars/getCurrentBuildTime.groovy') + binding.setProperty('currentBuild', new ClassMock()) + } + + @Test + void test() throws Exception { + def ret = script.call() + printCallStack() + assertTrue(ret.trim() ? true : false) + } + +} diff --git a/vars/README.md b/vars/README.md index 2ca59a42e..0eb6ff590 100644 --- a/vars/README.md +++ b/vars/README.md @@ -716,6 +716,15 @@ Then put all togeder in a simple JSON file. * buildNumber: the build id. Mandatory * returnData: whether to return a data structure with the build details then other steps can consume them. Optional. Default false +## getCurrentBuildTime +Returns the timestamp formatted in xs:dateTime. + +See https://javadoc.jenkins-ci.org/hudson/model/Run.html#getTimestampString2-- + +``` +getCurrentBuildTime() +``` + ## getFlakyJobName Get the flaky job name in a given multibranch pipeline. @@ -1171,6 +1180,7 @@ Pull Request details. * *labels*: Filter by labels. Optional * *title*: Filter by title (contains format). Mandatory +* *state*: Filter by state {open|closed|merged|all} (default "open"). Optional NOTE: It uses `githubPullRequests` diff --git a/vars/getCurrentBuildTime.groovy b/vars/getCurrentBuildTime.groovy new file mode 100644 index 000000000..d7f882766 --- /dev/null +++ b/vars/getCurrentBuildTime.groovy @@ -0,0 +1,32 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. 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. + +import com.cloudbees.groovy.cps.NonCPS + +/** + Returns the timestamp formatted in xs:dateTime. + + See https://javadoc.jenkins-ci.org/hudson/model/Run.html#getTimestampString2-- +*/ +def call(String branch){ + return getTimestampString2() +} + +@NonCPS +def getTimestampString2() { + return currentBuild.getRawBuild().getTimestampString2() +} diff --git a/vars/getCurrentBuildTime.txt b/vars/getCurrentBuildTime.txt new file mode 100644 index 000000000..8a3cdeaae --- /dev/null +++ b/vars/getCurrentBuildTime.txt @@ -0,0 +1,7 @@ +Returns the timestamp formatted in xs:dateTime. + +See https://javadoc.jenkins-ci.org/hudson/model/Run.html#getTimestampString2-- + +``` +getCurrentBuildTime() +```