Skip to content

Commit

Permalink
Merge branch 'release/v0.2.0' into readme_use-case
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Abnitski <[email protected]>
  • Loading branch information
abnitski-ilya authored Oct 23, 2024
2 parents 9f2e5b4 + fd4f407 commit 1c61d27
Show file tree
Hide file tree
Showing 27 changed files with 341 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .github/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inputs:
jdkVersion:
description: "JDK version"
required: false
default: "11"
default: "17"
mavenVersion:
description: "Maven version"
required: false
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/hpi-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
java-version: '17'
cache: maven

- name: Build Jenkins Plugin into .hpi
Expand Down Expand Up @@ -52,9 +52,9 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
java-version: '17'
cache: maven

- name: Run Unit Tests with Maven
shell: bash
run: ./mvnw test
run: ./mvnw test
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
* Copyright IBA Group 2022
*/

buildPlugin(useContainerAgent: true, tests: [[skip: 'true']], configurations: [[ platform: 'linux', jdk: '11' ]])
buildPlugin(useContainerAgent: true, tests: [[skip: 'true']], configurations: [[ platform: 'linux', jdk: '17' ]])
66 changes: 44 additions & 22 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.78</version>
<version>4.78</version> <!-- See https://github.com/jenkinsci/plugin-pom/releases for available versions-->
<relativePath />
</parent>

Expand All @@ -19,21 +19,31 @@


<properties>
<revision>0.2.0-</revision>
<revision>0.2.0</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.414.3</jenkins.version>
<java.version>11</java.version>
<kotlin.version>1.8.21</kotlin.version>
<java.version>17</java.version>
<kotlin.version>1.9.20</kotlin.version>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
<sezpoz.version>1.13</sezpoz.version>
<okhttp3.version>4.10.0</okhttp3.version>
<zowekotlinsdk.version>0.5.0-rc.1</zowekotlinsdk.version>
<zowekotlinsdk.version>0.5.0-rc.11</zowekotlinsdk.version>
<kotest.version>5.6.1</kotest.version>
<kotlin.code.style>official</kotlin.code.style>
<kotlin.compiler.jvmTarget>11</kotlin.compiler.jvmTarget>
<kotlin.compiler.jvmTarget>17</kotlin.compiler.jvmTarget>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spotbugs.threshold>High</spotbugs.threshold>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>

<sonar.sourceEncoding>UTF-8</sonar.sourceEncoding>
<sonar.organization>zowe</sonar.organization>
<sonar.projectKey>zowe_zowe-zdevops-jenkins-plugin</sonar.projectKey>
<sonar.projectName>zowe-zdevops-jenkins-plugin</sonar.projectName>
<sonar.projectVersion>project.version</sonar.projectVersion>
<sonar.language>kotlin</sonar.language>
<sonar.links.scm>https://github.com/zowe/zowe-zdevops-jenkins-plugin</sonar.links.scm>

<maven.compiler.release>17</maven.compiler.release>
</properties>

<licenses>
Expand Down Expand Up @@ -133,10 +143,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.13.0</version>
<configuration>
<source>11</source>
<target>11</target>
<source>17</source>
<target>17</target>
</configuration>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
Expand Down Expand Up @@ -302,19 +312,19 @@
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>2.9.0</version>
<version>2.11.0</version>
</dependency>

<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-gson</artifactId>
<version>2.9.0</version>
<version>2.11.0</version>
</dependency>

<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-scalars</artifactId>
<version>2.9.0</version>
<version>2.11.0</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -365,22 +375,12 @@
<version>2.10.1</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>annotation-indexer</artifactId>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
Expand Down Expand Up @@ -429,6 +429,28 @@
<scope>test</scope>
</dependency>

<!-- Jenkins plug-ins -->

<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>annotation-indexer</artifactId>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
</dependency>

</dependencies>

<repositories>
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/org/zowe/zdevops/classic/AbstractBuildStep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.kohsuke.stapler.QueryParameter
import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.zdevops.Messages
import org.zowe.zdevops.config.ZOSConnectionList
import org.zowe.zdevops.utils.validateConnection
import java.io.IOException
import java.io.PrintWriter
import java.io.StringWriter
Expand Down Expand Up @@ -71,6 +72,8 @@ abstract class AbstractBuildStep(val connectionName: String) : Builder(), Simple
connURL.host, connURL.port.toString(), connection.username, connection.password, connURL.protocol
)

validateConnection(zosConnection)

perform(build, launcher, listener, zosConnection)
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ constructor(
val primary: Int = 1,
var secondary: Int,
var recFm: RecordFormat,
var failOnExist: Boolean = false,
) : AbstractBuildStep(connectionName){

private var volser: String? = null
Expand Down Expand Up @@ -177,7 +178,8 @@ constructor(
dataClass,
avgBlk,
dsnType,
dsModel
dsModel,
failOnExist,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import org.zowe.zdevops.Messages
import org.zowe.zdevops.classic.AbstractBuildStep
import org.zowe.zdevops.logic.deleteDatasetOrMember
import org.zowe.zdevops.utils.validateDatasetName
import org.zowe.zdevops.utils.validateFieldIsNotEmpty
import org.zowe.zdevops.utils.validateMemberName

class DeleteDatasetStep
Expand All @@ -38,6 +37,7 @@ constructor(
connectionName: String,
val dsn: String,
val member: String?,
val failOnNotExist: Boolean = false ,
) : AbstractBuildStep(connectionName) {

override fun perform(
Expand All @@ -46,7 +46,7 @@ constructor(
listener: BuildListener,
zosConnection: ZOSConnection
) {
deleteDatasetOrMember(dsn, member, zosConnection, listener)
deleteDatasetOrMember(dsn, member, zosConnection, listener, failOnNotExist)
}

@Extension
Expand All @@ -67,10 +67,14 @@ constructor(
* Checks if the member name is valid
*
* @param member The dataset member name
* @return FormValidation.ok() if the member name is valid, or an error message otherwise
* @return FormValidation.ok() if either the member name is valid or is not provided, or an error message otherwise
*/
fun doCheckMember(@QueryParameter member: String): FormValidation? {
return validateMemberName(member)?: validateFieldIsNotEmpty(member)
return if (member.isNotBlank()) {
validateMemberName(member)
} else {
FormValidation.ok()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class DeleteDatasetsByMaskStep
constructor(
connectionName: String,
val dsnMask: String,
val failOnNotExist: Boolean = false,
) : AbstractBuildStep(connectionName) {

override fun perform(
Expand All @@ -39,7 +40,7 @@ constructor(
listener: BuildListener,
zosConnection: ZOSConnection
) {
deleteDatasetsByMask(dsnMask, zosConnection, listener)
deleteDatasetsByMask(dsnMask, zosConnection, listener, failOnNotExist)
}

@Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ constructor(
val linkBuilder: (String?, String, String) -> String = { jobUrl, jobName, jobId ->
"${jobUrl}ws/${jobName}.${jobId}/*view*/"
}
val returnCode = submitJobSync(jobName, zosConnection, listener, workspace, build.getEnvironment(listener)["JOB_URL"], linkBuilder)
if (checkRC && !returnCode.equals("CC 0000")) {
val jobResult = submitJobSync(jobName, zosConnection, listener, workspace, build.getEnvironment(listener)["JOB_URL"], linkBuilder)
if (checkRC && !jobResult.equals("CC 0000")) {
throw AbortException("Job RC code is not 0000")
}
} else {
Expand Down
13 changes: 6 additions & 7 deletions src/main/kotlin/org/zowe/zdevops/config/ZOSConnection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
* Copyright IBA Group 2022
*/

package org.zowe.zdevops.config;
package org.zowe.zdevops.config

import com.cloudbees.plugins.credentials.CredentialsMatchers
import com.cloudbees.plugins.credentials.CredentialsProvider
import com.cloudbees.plugins.credentials.common.StandardCredentials
import com.cloudbees.plugins.credentials.common.StandardListBoxModel
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder
import org.zowe.kotlinsdk.zowe.client.sdk.zosfiles.ZosDsnList
import org.zowe.kotlinsdk.zowe.client.sdk.zosfiles.input.ListParams
import org.zowe.zdevops.Messages
import org.zowe.zdevops.declarative.jobs.zMessages
import hudson.Extension
import hudson.model.AbstractDescribableImpl
import hudson.model.Descriptor
Expand All @@ -32,6 +28,9 @@ import net.sf.json.JSONObject
import org.kohsuke.stapler.DataBoundConstructor
import org.kohsuke.stapler.QueryParameter
import org.kohsuke.stapler.StaplerRequest
import org.zowe.zdevops.Messages
import org.zowe.zdevops.declarative.jobs.zMessages
import org.zowe.zdevops.utils.getTestDatasetList
import java.io.IOException
import java.io.ObjectInputStream
import java.io.ObjectOutputStream
Expand Down Expand Up @@ -119,9 +118,9 @@ constructor(
val testConnection = org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection(
connURL.host, connURL.port.toString(), credentials.username, credentials.password.plainText, connURL.protocol
)
ZosDsnList(testConnection).listDsn(zMessages.zdevops_config_ZOSConnection_validation_testDS(), ListParams())
getTestDatasetList(testConnection)
}.onFailure {
return FormValidation.error(zMessages.zdevops_config_ZOSConnection_validation_error());
return FormValidation.error("${zMessages.zdevops_config_ZOSConnection_validation_error()}\n(${it.message})");
}
return FormValidation.ok(zMessages.zdevops_config_ZOSConnection_validation_success())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ import hudson.tasks.BuildStepDescriptor
import hudson.tasks.Builder
import jenkins.tasks.SimpleBuildStep
import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.zdevops.Messages
import org.zowe.zdevops.config.ZOSConnectionList
import org.zowe.zdevops.utils.getZoweZosConnection
import java.io.PrintWriter
import java.io.StringWriter
import java.net.URL
import java.nio.charset.StandardCharsets

abstract class AbstractZosmfAction : Builder(), SimpleBuildStep {
Expand All @@ -38,18 +36,8 @@ abstract class AbstractZosmfAction : Builder(), SimpleBuildStep {

override fun perform(run: Run<*, *>, workspace: FilePath, env: EnvVars, launcher: Launcher, listener: TaskListener) {
val connectionName = workspace.read().readBytes().toString(StandardCharsets.UTF_8)
val connection = ZOSConnectionList.resolve(connectionName) ?: let {
val zoweConnection = getZoweZosConnection(connectionName, listener)

val exception = IllegalArgumentException(Messages.zdevops_config_ZOSConnection_resolve_unknown(connectionName))
val sw = StringWriter()
exception.printStackTrace(PrintWriter(sw))
listener.logger.println(sw.toString())
throw exception
}
val connURL = URL(connection.url)
val zoweConnection = ZOSConnection(
connURL.host, connURL.port.toString(), connection.username, connection.password, connURL.protocol
)
runCatching {
perform(run, workspace, env, launcher, listener, zoweConnection)
}.onFailure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,24 @@ package org.zowe.zdevops.declarative
import hudson.EnvVars
import hudson.Extension
import hudson.FilePath
import hudson.model.*
import hudson.model.Run
import hudson.model.TaskListener
import org.jenkinsci.plugins.workflow.steps.Step
import org.jenkinsci.plugins.workflow.steps.StepContext
import org.jenkinsci.plugins.workflow.steps.StepDescriptor
import org.jenkinsci.plugins.workflow.steps.StepExecution
import org.kohsuke.stapler.DataBoundConstructor
import org.zowe.zdevops.utils.getZoweZosConnection
import org.zowe.zdevops.utils.validateConnection


class ZosmfStepDeclarative @DataBoundConstructor constructor(private val connectionName: String) : Step() {
override fun start(context: StepContext): StepExecution {
val listener: TaskListener? = context.get(TaskListener::class.java)
val zosConnection = getZoweZosConnection(connectionName, listener)

validateConnection(zosConnection)

return ZosmfExecution(connectionName, context)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ constructor(
private val dsOrg: DatasetOrganization,
private val primary: Int,
private var secondary: Int,
private var recFm: RecordFormat) :
private var recFm: RecordFormat,
private var failOnExist: Boolean = false) :
AbstractZosmfAction() {

private var volser: String? = null
Expand Down Expand Up @@ -126,7 +127,8 @@ constructor(
dataClass,
avgBlk,
dsnType,
dsModel
dsModel,
failOnExist,
)
}

Expand Down
Loading

0 comments on commit 1c61d27

Please sign in to comment.