Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [CI-14984]: fixed mergeRunStep issue #240

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Anshika2203
Copy link
Contributor

@Anshika2203 Anshika2203 commented Nov 6, 2024

Removed the pushed flag:
The pushed flag was unnecessary and potentially confusing
The logic now handles all cases without needing to track whether something was pushed

Simplified the loop logic:
Removed the conditional check if i != len(*steps)-1
Made the merge/no-merge decision more straightforward

Fixed the last step handling:
Always append the final cursor state after the loop
This ensures we don't lose any steps regardless of whether the last step was merged or not (which was the main issue).

Also added a function which checks that if image is non-default then it will not merge.

Jenkins pipeline which I mentioned in the ticket in now returning correct output.

pipeline:
  identifier: default
  name: default
  orgIdentifier: default
  projectIdentifier: default
  properties:
    ci:
      codebase:
        build: <+input>
  stages:
  - stage:
      identifier: build
      name: build
      spec:
        cloneCodebase: true
        execution:
          steps:
          - stepGroup:
              identifier: Stage__null645b44
              name: Checkout
              timeout: ""
          - stepGroup:
              identifier: Stage__null959e75
              name: Plugin Build
              steps:
              - step:
                  identifier: stagenull30d2ac
                  name: maven
                  spec:
                    command: mvn clean install                        package
                    envVariables:
                      ANT_HOME: /var/jenkins_home/tools/hudson.tasks.Ant_AntInstallation/ant1
                      M2_HOME: /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven1
                      MAVEN_HOME: /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven1
                      PATH+ANT: /var/jenkins_home/tools/hudson.tasks.Ant_AntInstallation/ant1/bin
                      PATH+GRADLE: /var/jenkins_home/tools/hudson.plugins.gradle.GradleInstallation/gradle1/bin
                      PATH+MAVEN: /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven1/bin
                    image: maven:latest
                    shell: Sh
                  timeout: ""
                  type: Run
              - step:
                  identifier: stagenull51182d
                  name: ant
                  spec:
                    command: ant build
                    envVariables:
                      ANT_HOME: /var/jenkins_home/tools/hudson.tasks.Ant_AntInstallation/ant1
                      M2_HOME: /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven1
                      MAVEN_HOME: /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven1
                      PATH+ANT: /var/jenkins_home/tools/hudson.tasks.Ant_AntInstallation/ant1/bin
                      PATH+GRADLE: /var/jenkins_home/tools/hudson.plugins.gradle.GradleInstallation/gradle1/bin
                      PATH+MAVEN: /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven1/bin
                    image: frekele/ant:latest
                    shell: Sh
                  timeout: ""
                  type: Run
              - step:
                  identifier: stagenulld802a5
                  name: gradle
                  spec:
                    command: gradle build
                    envVariables:
                      ANT_HOME: /var/jenkins_home/tools/hudson.tasks.Ant_AntInstallation/ant1
                      M2_HOME: /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven1
                      MAVEN_HOME: /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven1
                      PATH+ANT: /var/jenkins_home/tools/hudson.tasks.Ant_AntInstallation/ant1/bin
                      PATH+GRADLE: /var/jenkins_home/tools/hudson.plugins.gradle.GradleInstallation/gradle1/bin
                      PATH+MAVEN: /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven1/bin
                    image: gradle:latest
                    shell: Sh
                  timeout: ""
                  type: Run
              timeout: ""
          - stepGroup:
              identifier: Stage__null847254
              name: Code Analysis
              steps:
              - step:
                  identifier: stagenull7d2a33
                  name: sonarCube
                  spec:
                    envVariables:
                      ANT_HOME: /var/jenkins_home/tools/hudson.tasks.Ant_AntInstallation/ant1
                      M2_HOME: /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven1
                      MAVEN_HOME: /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven1
                      PATH+ANT: /var/jenkins_home/tools/hudson.tasks.Ant_AntInstallation/ant1/bin
                      PATH+GRADLE: /var/jenkins_home/tools/hudson.plugins.gradle.GradleInstallation/gradle1/bin
                      PATH+MAVEN: /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven1/bin
                      scannerHome: /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar1
                    image: aosapps/drone-sonar-plugin
                    settings:
                      sonar_host: <+input>
                      sonar_token: <+input>
                  timeout: ""
                  type: Plugin
              timeout: ""
        platform:
          arch: Amd64
          os: Linux
        runtime:
          spec: {}
          type: Cloud
      type: CI

@hemanthmantri
Copy link

Please add UTs and include a link to pipeline which shows the steps after conversion.

@Anshika2203
Copy link
Contributor Author

Please add UTs and include a link to pipeline which shows the steps after conversion.

Added UTs and passed alpine as a defaultImage variable.

@@ -62,13 +62,16 @@ type ProcessedTools struct {
var mavenGoals string
var gradleGoals string

var defaultAlpineImage string

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this image is being passed from the CLI then naming this variable using a particular image will be confusing. As per other places the more generic defaultImage makes more sense.

Copy link
Contributor

@jamie-harness jamie-harness Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree with that. @Anshika2203 please change naming

@@ -963,6 +965,10 @@ func canMergeSteps(step1, step2 *harness.Step) bool {
return false
}

if !hasDefaultOrNoImage(exec1) || !hasDefaultOrNoImage(exec2) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case where both step1 and step2 have no image, I assume they could be merged since the image matches?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants