Skip to content

Commit

Permalink
replace original methods
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoli Kalbasin <[email protected]>
  • Loading branch information
callbacksin committed Sep 20, 2024
1 parent 86fc047 commit 157a6f7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,46 @@
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBA Group 2023
* Copyright IBA Group 2024
*/

package org.zowe.zdevops.declarative.jobs

import hudson.*
import hudson.model.Run
import hudson.AbortException
import hudson.EnvVars
import hudson.Extension
import hudson.FilePath
import hudson.model.TaskListener
import org.jenkinsci.Symbol
import org.kohsuke.stapler.DataBoundConstructor
import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.zdevops.declarative.AbstractZosmfAction
import org.zowe.zdevops.declarative.AbstractZosmfActionWithResult
import org.zowe.zdevops.logic.performTsoCommand

/**
* A Jenkins Pipeline step for performing a TSO (Time Sharing Option) command on a z/OS system
* using the Declarative Pipeline syntax.
* Class that represents an action to perform a TSO command with a result in a declarative pipeline.
* This class extends {@code AbstractZosmfActionWithResult} and is designed to execute a TSO command
* via Zowe z/OSMF and return the command's output.
*
* This step allows you to execute TSO commands on a z/OS system and provides integration with
* Jenkins Pipelines for mainframe automation.
* @param acct the TSO account number.
* @param command the TSO command to be executed.
*/
class PerformTsoCommandDeclarative
/**
* Data-bound constructor for the {@code PerformTsoCommandDeclarative} step.
*
* @param acct The z/OS account under which to run the TSO command.
* @param command The TSO command to be executed.
*/
@DataBoundConstructor
constructor(
val acct: String,
val command: String,
) : AbstractZosmfAction() {

override val exceptionMessage: String = zMessages.zdevops_TSO_command_fail()
) : AbstractZosmfActionWithResult() {

/**
* Performs the TSO command execution step within a Jenkins Pipeline.
*
* @param run The current Jenkins build run.
* @param workspace The workspace where the build is executed.
* @param env The environment variables for the build.
* @param launcher The build launcher.
* @param listener The build listener.
* @param zosConnection The z/OS connection to execute the TSO command.
*/
override fun perform(
run: Run<*, *>,
override fun run(
workspace: FilePath,
env: EnvVars,
launcher: Launcher,
listener: TaskListener,
zosConnection: ZOSConnection
) {
performTsoCommand(zosConnection, listener, acct, command)
envVars: EnvVars,
zoweZOSConnection: ZOSConnection
): String {
return performTsoCommand(zoweZOSConnection, listener, acct, command)
?: throw AbortException("TSO command execution returned an empty result")
}

/**
* Descriptor for the {@code PerformTsoCommandDeclarative} step.
*
* This descriptor provides information about the step and makes it available for use
* within Jenkins Pipelines.
*/
@Symbol("performTsoCommand")
@Extension
class DescriptorImpl : Companion.DefaultBuildDescriptor("Perform TSO command Declarative")
}
class DescriptorImpl : Companion.DefaultStepDescriptor(functionName = "performTsoCommandWithResult")
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,46 @@
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBA Group 2022
* Copyright IBA Group 2024
*/

package org.zowe.zdevops.declarative.jobs

import hudson.*
import hudson.model.Run
import hudson.EnvVars
import hudson.Extension
import hudson.FilePath
import hudson.model.TaskListener
import org.jenkinsci.Symbol
import org.kohsuke.stapler.DataBoundConstructor
import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.zdevops.declarative.AbstractZosmfAction
import org.zowe.zdevops.declarative.AbstractZosmfActionWithResult
import org.zowe.zdevops.logic.submitJobSync

class SubmitJobSyncStepDeclarative @DataBoundConstructor constructor(private val fileToSubmit: String):
AbstractZosmfAction() {

override val exceptionMessage: String = zMessages.zdevops_declarative_ZOSJobs_submitted_fail(fileToSubmit)
/**
* Class that represents an action to submit a z/OS job and retrieve the return code in a declarative pipeline.
* This class extends {@code AbstractZosmfActionWithResult} and is designed to submit a job via Zowe z/OSMF
* and return the job's return code.
*
* @param fileToSubmit the path to the file containing the JCL to be submitted.
*/
class SubmitJobSyncStepDeclarative
@DataBoundConstructor
constructor(val fileToSubmit: String)
: AbstractZosmfActionWithResult() {

override fun perform(
run: Run<*, *>,
override fun run(
workspace: FilePath,
env: EnvVars,
launcher: Launcher,
listener: TaskListener,
zosConnection: ZOSConnection
) {
val workspacePath = FilePath(null, workspace.remote.replace(workspace.name,""))
val linkBuilder: (String?, String, String) -> String = { buildUrl, jobName, jobId ->
"$buildUrl/execution/node/3/ws/${jobName}.${jobId}/*view*/"
}
submitJobSync(fileToSubmit, zosConnection, listener, workspacePath, env["BUILD_URL"], linkBuilder)
envVars: EnvVars,
zoweZOSConnection: ZOSConnection
): String {
val workspacePath = FilePath(null, workspace.remote.replace(workspace.name,""))
val linkBuilder: (String?, String, String) -> String = { buildUrl, jobName, jobId ->
"$buildUrl/execution/node/3/ws/${jobName}.${jobId}/*view*/"
}
return submitJobSync(fileToSubmit, zoweZOSConnection,
listener, workspacePath, envVars["BUILD_URL"], linkBuilder)
}

@Symbol("submitJobSync")
@Extension
class DescriptorImpl : Companion.DefaultBuildDescriptor("Submit Job Synchronously Declarative")
class DescriptorImpl : Companion.DefaultStepDescriptor(functionName = "submitJobSyncWithResult")
}

0 comments on commit 157a6f7

Please sign in to comment.