code: public static ArtifactoryServer getArtifactoryServer(Run build, FilePath ws, StepContext context, String serverId) throws IOException, InterruptedException {
          String buildNumber = BuildUniqueIdentifierHelper.getBuildNumber(build);
          BuildDataFile buildDataFile = readBuildDataFile(ws, buildNumber, CreateServerStep.STEP_NAME, serverId);
          // If the server has not been configured as part of the declarative pipeline script, get its details from it.
          if (buildDataFile == null) {
              // This server ID has not been configured as part of the declarative pipeline script.
              // Let's get it from the Jenkins configuration.
              GetArtifactoryServerExecutor getArtifactoryServerExecutor = new GetArtifactoryServerExecutor(build, context, serverId);
              getArtifactoryServerExecutor.execute();
              return getArtifactoryServerExecutor.getArtifactoryServer();
          }
          JsonNode jsonNode = buildDataFile.get(CreateServerStep.STEP_NAME);
          ArtifactoryServer server = Utils.mapper().treeToValue(jsonNode, ArtifactoryServer.class);
          String credentialsId = jsonNode.get("credentialsId").asText();
          if (!credentialsId.isEmpty()) {
              server.setCredentialsId(credentialsId);
          } else {
              server.setUsername(jsonNode.get("username").asText());
              server.setPassword(jsonNode.get("password").asText());
          }
          return server;
      }
docs: Get Artifactory server from global server configuration or from previous rtServer{...} scope.
  
  @param build    - Step's build.
  @param ws       - Step's workspace.
  @param context  - Step's context.
  @param serverId - The server id. Can be defined from global server configuration or from previous rtServer{...} scope.
  @return Artifactory server.