diff --git a/README.md b/README.md index b2d81113f..16c856ce2 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ To run unit tests execute the following command: #### Running integration tests Before running the integration tests, set the following environment variables. -*JENKINS_ARTIFACTORY_URL*
+*JENKINS_PLATFORM_URL*
*JENKINS_ARTIFACTORY_USERNAME*
*JENKINS_ARTIFACTORY_PASSWORD*
*JENKINS_ARTIFACTORY_DOCKER_PUSH_DOMAIN* (For example, server-docker-local.jfrog.io)
diff --git a/ci/appveyor.yml b/ci/appveyor.yml index d922efdbc..5d0e72fe4 100644 --- a/ci/appveyor.yml +++ b/ci/appveyor.yml @@ -13,7 +13,7 @@ # # = Override credentials in Appveyor in case of a fork = # 1. In the project at Appveyor - Go to settings -> Environment. -# 2. Override 'JENKINS_ARTIFACTORY_URL' and 'JENKINS_ARTIFACTORY_USERNAME'. +# 2. Override 'JENKINS_PLATFORM_URL' and 'JENKINS_ARTIFACTORY_USERNAME'. # 3. Override 'JENKINS_ARTIFACTORY_PASSWORD' with variable encryption. stack: jdk 8, node 8, python 3.7.9 @@ -34,8 +34,8 @@ environment: services: - docker before_test: - - cmd: "choco install maven --version 3.3.9.2 -i -s %JENKINS_ARTIFACTORY_URL%/api/nuget/choco -u %JENKINS_ARTIFACTORY_USERNAME% -p %JENKINS_ARTIFACTORY_PASSWORD%" - - cmd: "choco install gradle --version 6.5.1 -i -s %JENKINS_ARTIFACTORY_URL%/api/nuget/choco -u %JENKINS_ARTIFACTORY_USERNAME% -p %JENKINS_ARTIFACTORY_PASSWORD%" + - cmd: "choco install maven --version 3.3.9.2 -i -s %JENKINS_PLATFORM_URL%/artifactory/api/nuget/choco -u %JENKINS_ARTIFACTORY_USERNAME% -p %JENKINS_ARTIFACTORY_PASSWORD%" + - cmd: "choco install gradle --version 6.5.1 -i -s %JENKINS_PLATFORM_URL%/artifactory/api/nuget/choco -u %JENKINS_ARTIFACTORY_USERNAME% -p %JENKINS_ARTIFACTORY_PASSWORD%" - cmd: refreshenv - cmd: pip install conan -q - cmd: "C:\\Python37-x64\\python -m venv pip-venv" diff --git a/src/main/java/org/jfrog/hudson/AbstractBuildWrapperDescriptor.java b/src/main/java/org/jfrog/hudson/AbstractBuildWrapperDescriptor.java index 4d9bf75b4..fbbac097a 100644 --- a/src/main/java/org/jfrog/hudson/AbstractBuildWrapperDescriptor.java +++ b/src/main/java/org/jfrog/hudson/AbstractBuildWrapperDescriptor.java @@ -61,12 +61,12 @@ public boolean configure(StaplerRequest req, JSONObject json) { } /** - * Returns the list of {@link org.jfrog.hudson.ArtifactoryServer} configured. + * Returns the list of {@link JFrogPlatformInstance} configured. * * @return can be empty but never null. */ - public List getArtifactoryServers() { - return RepositoriesUtils.getArtifactoryServers(); + public List getJfrogInstances() { + return RepositoriesUtils.getJFrogPlatformInstances(); } @SuppressWarnings("unused") @@ -95,7 +95,7 @@ protected RefreshServerResponse refreshResolversFromArtifactory(String url, Stri String password, boolean overrideCredentials) { RefreshServerResponse response = new RefreshServerResponse(); CredentialsConfig credentialsConfig = new CredentialsConfig(username, password, credentialsId, overrideCredentials); - ArtifactoryServer artifactoryServer = RepositoriesUtils.getArtifactoryServer(url, RepositoriesUtils.getArtifactoryServers()); + ArtifactoryServer artifactoryServer = RepositoriesUtils.getArtifactoryServer(url); try { List virtualRepositories = refreshVirtualRepositories(artifactoryServer, credentialsConfig); response.setVirtualRepositories(virtualRepositories); @@ -124,7 +124,7 @@ protected RefreshServerResponse refreshDeployersFromArtifactory(String url, Stri String password, boolean overrideCredentials, boolean refreshUserPlugins) { RefreshServerResponse response = new RefreshServerResponse(); CredentialsConfig credentialsConfig = new CredentialsConfig(username, password, credentialsId, overrideCredentials); - ArtifactoryServer artifactoryServer = RepositoriesUtils.getArtifactoryServer(url, RepositoriesUtils.getArtifactoryServers()); + ArtifactoryServer artifactoryServer = RepositoriesUtils.getArtifactoryServer(url); try { response.setRepositories(refreshRepositories(artifactoryServer, credentialsConfig)); if (refreshUserPlugins) { diff --git a/src/main/java/org/jfrog/hudson/ArtifactoryBuilder.java b/src/main/java/org/jfrog/hudson/ArtifactoryBuilder.java index a8ab0008b..e4f072a1c 100644 --- a/src/main/java/org/jfrog/hudson/ArtifactoryBuilder.java +++ b/src/main/java/org/jfrog/hudson/ArtifactoryBuilder.java @@ -17,15 +17,17 @@ package org.jfrog.hudson; import com.cloudbees.plugins.credentials.common.StandardListBoxModel; +import com.google.common.collect.Lists; import hudson.Extension; import hudson.model.BuildableItem; import hudson.model.BuildableItemWithBuildWrappers; import hudson.model.Descriptor; import hudson.model.Item; -import hudson.util.Secret; import hudson.security.ACL; import hudson.util.FormValidation; import hudson.util.ListBoxModel; +import hudson.util.Secret; +import hudson.util.XStream2; import jenkins.model.GlobalConfiguration; import jenkins.model.Jenkins; import net.sf.json.JSONNull; @@ -42,6 +44,7 @@ import org.jfrog.hudson.jfpipelines.JFrogPipelinesServer; import org.jfrog.hudson.util.Credentials; import org.jfrog.hudson.util.RepositoriesUtils; +import org.jfrog.hudson.util.converters.ArtifactoryBuilderConverter; import org.jfrog.hudson.util.plugins.PluginsUtils; import org.kohsuke.stapler.AncestorInPath; import org.kohsuke.stapler.QueryParameter; @@ -73,6 +76,11 @@ public class ArtifactoryBuilder extends GlobalConfiguration { public static final class DescriptorImpl extends Descriptor { private boolean useCredentialsPlugin; + private List jfrogInstances; + /** + * @deprecated: Use org.jfrog.hudson.ArtifactoryBuilder.DescriptorImpl#getJfrogInstances() + */ + @Deprecated private List artifactoryServers; private JFrogPipelinesServer jfrogPipelinesServer = new JFrogPipelinesServer(); @@ -92,26 +100,26 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item project) { } /** - * Performs on-the-fly validation of the form field 'ServerId'. + * Performs on-the-fly validation of the form field 'InstanceId'. * * @param value This parameter receives the value that the user has typed. * @return Indicates the outcome of the validation. This is sent to the browser. */ @SuppressWarnings("unused") - public FormValidation doCheckServerId(@QueryParameter String value) { + public FormValidation doCheckInstanceId(@QueryParameter String value) { if (value.length() == 0) { return FormValidation.error("Please set server ID"); } - List artifactoryServers = RepositoriesUtils.getArtifactoryServers(); - if (artifactoryServers == null) { + List JFrogPlatformInstances = RepositoriesUtils.getJFrogPlatformInstances(); + if (JFrogPlatformInstances == null) { return FormValidation.ok(); } int countServersByValueAsName = 0; - for (ArtifactoryServer server : artifactoryServers) { - if (server.getServerId().equals(value)) { + for (JFrogPlatformInstance JFrogPlatformInstance : JFrogPlatformInstances) { + if (JFrogPlatformInstance.getId().equals(value)) { countServersByValueAsName++; if (countServersByValueAsName > 1) { - return FormValidation.error("Duplicated server ID"); + return FormValidation.error("Duplicated JFrog platform instances ID"); } } } @@ -121,9 +129,10 @@ public FormValidation doCheckServerId(@QueryParameter String value) { @SuppressWarnings("unused") @RequirePOST public FormValidation doTestConnection( - @QueryParameter("artifactoryUrl") final String url, - @QueryParameter("artifactory.timeout") final String timeout, - @QueryParameter("artifactory.bypassProxy") final boolean bypassProxy, + @QueryParameter("url") final String url, + @QueryParameter("artifactoryUrl") final String artifactoryUrl, + @QueryParameter("instance.timeout") final String timeout, + @QueryParameter("instance.bypassProxy") final boolean bypassProxy, @QueryParameter("useCredentialsPlugin") final boolean useCredentialsPlugin, @QueryParameter("credentialsId") final String deployerCredentialsId, @QueryParameter("username") final String deployerCredentialsUsername, @@ -132,17 +141,20 @@ public FormValidation doTestConnection( if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) { return FormValidation.error("Testing the connection requires 'Administer' permission"); } - if (StringUtils.isBlank(url)) { - return FormValidation.error("Please set a valid Artifactory URL"); + if (StringUtils.isBlank(artifactoryUrl) && StringUtils.isBlank(url)) { + return FormValidation.error("Please set a valid Artifactory or platform URL"); } if (connectionRetry < 0) { return FormValidation.error("Connection Retries can not be less then 0"); } - + if (StringUtils.isEmpty(deployerCredentialsId) && (StringUtils.isEmpty(deployerCredentialsUsername) || StringUtils.isEmpty(deployerCredentialsPassword))) { + return FormValidation.error("Please set a valid credentials"); + } + String targetArtUrl = StringUtils.isBlank(artifactoryUrl) ? StringUtils.removeEnd(url, "/") + "/artifactory" : artifactoryUrl; String accessToken = StringUtils.EMPTY; String username = StringUtils.EMPTY; String password = StringUtils.EMPTY; - + StringCredentials accessTokenCredentials = PluginsUtils.accessTokenCredentialsLookup(deployerCredentialsId, null); if (accessTokenCredentials != null) { accessToken = accessTokenCredentials.getSecret().getPlainText(); @@ -159,9 +171,9 @@ public FormValidation doTestConnection( ArtifactoryBuildInfoClient client; if (StringUtils.isNotEmpty(username) || StringUtils.isNotEmpty(accessToken)) { - client = new ArtifactoryBuildInfoClient(url, username, password, accessToken, new NullLog()); + client = new ArtifactoryBuildInfoClient(targetArtUrl, username, password, accessToken, new NullLog()); } else { - client = new ArtifactoryBuildInfoClient(url, new NullLog()); + client = new ArtifactoryBuildInfoClient(targetArtUrl, new NullLog()); } try { @@ -182,7 +194,7 @@ public FormValidation doTestConnection( } catch (Exception e) { return FormValidation.error(e.getMessage()); } - return FormValidation.ok("Found Artifactory " + version.toString()); + return FormValidation.ok("Found Artifactory " + version.toString() + " on " + targetArtUrl); } finally { client.close(); } @@ -250,7 +262,7 @@ public boolean configure(StaplerRequest req, JSONObject o) throws FormException Jenkins jenkins = Jenkins.getInstanceOrNull(); if (jenkins != null && jenkins.hasPermission(Jenkins.ADMINISTER)) { boolean useCredentialsPlugin = (Boolean) o.get("useCredentialsPlugin"); - configureArtifactoryServers(req, o); + configureJfrogServers(req, o); configureJFrogPipelinesServer(o); if (useCredentialsPlugin && !this.useCredentialsPlugin) { resetJobsCredentials(); @@ -263,21 +275,26 @@ public boolean configure(StaplerRequest req, JSONObject o) throws FormException throw new FormException("User doesn't have permissions to save", "Server ID"); } - private void configureArtifactoryServers(StaplerRequest req, JSONObject o) throws FormException { - List artifactoryServers = null; - Object artifactoryServerObj = o.get("artifactoryServer"); // an array or single object - if (!JSONNull.getInstance().equals(artifactoryServerObj)) { - artifactoryServers = req.bindJSONToList(ArtifactoryServer.class, artifactoryServerObj); + private void configureJfrogServers(StaplerRequest req, JSONObject o) throws FormException { + List jfrogInstances = Lists.newArrayList(); + Object jfrogInstancesObj = o.get("jfrogInstances"); // an array or single object + if (!JSONNull.getInstance().equals(jfrogInstancesObj)) { + jfrogInstances = req.bindJSONToList(JFrogPlatformInstance.class, jfrogInstancesObj); } - if (!isServerIDConfigured(artifactoryServers)) { - throw new FormException("Please set the Artifactory server ID.", "ServerID"); + if (!isJfrogServersIDConfigured(jfrogInstances)) { + throw new FormException("Please set the Instance ID.", "InstanceID"); } - if (isServerDuplicated(artifactoryServers)) { - throw new FormException("The Artifactory server ID you have entered is already configured", "Server ID"); + if (isInstanceDuplicated(jfrogInstances)) { + throw new FormException("The JFrog instance ID you have entered is already configured", "Instance ID"); } - setArtifactoryServers(artifactoryServers); + + if (isEmptyUrls(jfrogInstances)) { + throw new FormException("Please set the The JFrog Platform or Artifactory URL", "URL"); + } + fillEmptyServers(jfrogInstances); + setJfrogInstances(jfrogInstances); } private void configureJFrogPipelinesServer(JSONObject o) { @@ -291,7 +308,7 @@ private void configureJFrogPipelinesServer(JSONObject o) { } private void resetServersCredentials() { - for (ArtifactoryServer server : artifactoryServers) { + for (JFrogPlatformInstance server : jfrogInstances) { if (server.getResolverCredentialsConfig() != null) { server.getResolverCredentialsConfig().deleteCredentials(); } @@ -352,32 +369,74 @@ public void setUseCredentialsPlugin(boolean useCredentialsPlugin) { this.useCredentialsPlugin = useCredentialsPlugin; } - private boolean isServerDuplicated(List artifactoryServers) { + private boolean isEmptyUrls(List JfrogInstances) { + if (JfrogInstances == null) { + return false; + } + for (JFrogPlatformInstance instance : JfrogInstances) { + if (StringUtils.isBlank(instance.getUrl()) && StringUtils.isBlank(instance.getArtifactoryServer().getArtifactoryUrl())) { + return true; + } + } + return false; + } + + private boolean fillEmptyServers(List JfrogInstances) { + if (JfrogInstances == null) { + return false; + } + for (JFrogPlatformInstance instance : JfrogInstances) { + if (StringUtils.isBlank(instance.getArtifactoryServer().getArtifactoryUrl())) { + instance.getArtifactoryServer().setArtifactoryUrl(instance.getUrl() + "/artifactory"); + } + } + return false; + } + + private boolean isInstanceDuplicated(List JfrogInstances) { Set serversNames = new HashSet<>(); - if (artifactoryServers == null) { + if (JfrogInstances == null) { return false; } - for (ArtifactoryServer server : artifactoryServers) { - String name = server.getServerId(); - if (serversNames.contains(name)) { + for (JFrogPlatformInstance instance : JfrogInstances) { + String id = instance.getId(); + if (serversNames.contains(id)) { return true; } - serversNames.add(name); + serversNames.add(id); } return false; } - private boolean isServerIDConfigured(List artifactoryServers) { - if (artifactoryServers == null) { + private boolean isJfrogServersIDConfigured(List JfrogInstances) { + if (JfrogInstances == null) { return true; } - for (ArtifactoryServer server : artifactoryServers) { - String name = server.getServerId(); - if (StringUtils.isBlank(name)) { + for (JFrogPlatformInstance server : JfrogInstances) { + String platformId = server.getId(); + String artifactoryId = server.getArtifactoryServer().getServerId(); + if (StringUtils.isBlank(platformId) || StringUtils.isBlank(artifactoryId)) { return false; } } return true; } + + public List getJfrogInstances() { + return jfrogInstances; + } + + public void setJfrogInstances(List jfrogInstances) { + this.jfrogInstances = jfrogInstances; + } + + /** + * Page Converter + */ + public static final class ConverterImpl extends ArtifactoryBuilderConverter { + public ConverterImpl(XStream2 xstream) { + super(xstream); + } + } } } diff --git a/src/main/java/org/jfrog/hudson/ArtifactoryRedeployPublisher.java b/src/main/java/org/jfrog/hudson/ArtifactoryRedeployPublisher.java index cda4a518c..66636d89e 100644 --- a/src/main/java/org/jfrog/hudson/ArtifactoryRedeployPublisher.java +++ b/src/main/java/org/jfrog/hudson/ArtifactoryRedeployPublisher.java @@ -425,7 +425,7 @@ public DescriptorImpl getDescriptor() { } public ArtifactoryServer getArtifactoryServer() { - return RepositoriesUtils.getArtifactoryServer(getArtifactoryName(), getDescriptor().getArtifactoryServers()); + return RepositoriesUtils.getArtifactoryServer(getArtifactoryName()); } private Result getTreshold() { @@ -525,9 +525,7 @@ public RefreshServerResponse refreshFromArtifactory(String url, String credentia CredentialsConfig credentialsConfig = new CredentialsConfig(username, password, credentialsId, overrideCredentials); try { - ArtifactoryServer artifactoryServer = RepositoriesUtils.getArtifactoryServer( - url, getArtifactoryServers() - ); + ArtifactoryServer artifactoryServer = RepositoriesUtils.getArtifactoryServer(url); List releaseRepositories = refreshRepositories(artifactoryServer, credentialsConfig); List userPluginKeys = refreshUserPlugins(artifactoryServer, credentialsConfig); @@ -552,12 +550,12 @@ public String getDisplayName() { } /** - * Returns the list of {@link ArtifactoryServer} configured. + * Returns the list of {@link JFrogPlatformInstance} configured. * * @return can be empty but never null. */ - public List getArtifactoryServers() { - return RepositoriesUtils.getArtifactoryServers(); + public List getJfrogInstances() { + return RepositoriesUtils.getJFrogPlatformInstances(); } public boolean isJiraPluginEnabled() { diff --git a/src/main/java/org/jfrog/hudson/ArtifactoryServer.java b/src/main/java/org/jfrog/hudson/ArtifactoryServer.java index ba95551b6..009230239 100644 --- a/src/main/java/org/jfrog/hudson/ArtifactoryServer.java +++ b/src/main/java/org/jfrog/hudson/ArtifactoryServer.java @@ -40,27 +40,29 @@ import org.jfrog.hudson.util.JenkinsBuildInfoLog; import org.jfrog.hudson.util.RepositoriesUtils; import org.jfrog.hudson.util.converters.ArtifactoryServerConverter; -import org.kohsuke.stapler.DataBoundConstructor; import java.io.IOException; import java.io.Serializable; -import java.util.*; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import static org.jfrog.hudson.JFrogPlatformInstance.DEFAULT_CONNECTION_TIMEOUT; +import static org.jfrog.hudson.JFrogPlatformInstance.DEFAULT_DEPLOYMENT_THREADS_NUMBER; import static org.jfrog.hudson.util.ProxyUtils.createProxyConfiguration; /** - * Represents an artifactory instance. + * Represents an instance of jenkins artifactory configuration page. * * @author Yossi Shaul */ public class ArtifactoryServer implements Serializable { private static final Logger log = Logger.getLogger(ArtifactoryServer.class.getName()); - private static final int DEFAULT_CONNECTION_TIMEOUT = 300; // 5 Minutes - private static final int DEFAULT_DEPLOYMENT_THREADS_NUMBER = 3; - private final String url; + private String url; private String id; // Network timeout in seconds to use both for connection establishment and for unanswered requests private int timeout = DEFAULT_CONNECTION_TIMEOUT; @@ -92,15 +94,14 @@ public class ArtifactoryServer implements Serializable { private CredentialsConfig resolverCredentialsConfig; - @DataBoundConstructor public ArtifactoryServer(String serverId, String artifactoryUrl, CredentialsConfig deployerCredentialsConfig, CredentialsConfig resolverCredentialsConfig, int timeout, boolean bypassProxy, Integer connectionRetry, Integer deploymentThreads) { this.url = StringUtils.removeEnd(artifactoryUrl, "/"); + this.id = serverId; this.deployerCredentialsConfig = deployerCredentialsConfig; this.resolverCredentialsConfig = resolverCredentialsConfig; this.timeout = timeout > 0 ? timeout : DEFAULT_CONNECTION_TIMEOUT; this.bypassProxy = bypassProxy; - this.id = serverId; this.connectionRetry = connectionRetry != null ? connectionRetry : 3; this.deploymentThreads = deploymentThreads != null && deploymentThreads > 0 ? deploymentThreads : DEFAULT_DEPLOYMENT_THREADS_NUMBER; } @@ -113,6 +114,10 @@ public void setServerId(String id) { this.id = id; } + public void setArtifactoryUrl(String url) { + this.url = url; + } + public String getArtifactoryUrl() { return url != null ? url : getServerId(); } @@ -133,14 +138,6 @@ public boolean isBypassProxy() { return bypassProxy; } - // To populate the dropdown list from the jelly - public List getConnectionRetries() { - List items = new ArrayList(); - for (int i = 0; i < 10; i++) { - items.add(i); - } - return items; - } public int getConnectionRetry() { if (connectionRetry == null) { @@ -153,32 +150,6 @@ public void setConnectionRetry(int connectionRetry) { this.connectionRetry = connectionRetry; } - /** - * Return number of deployment threads. - * To populate the dropdown list from the jelly: - * - */ - @SuppressWarnings("unused") - public List getDeploymentsThreads() { - List items = new ArrayList<>(); - for (int i = 1; i <= 10; i++) { - items.add(i); - } - return items; - } - - /** - * Set the number of deployment threads. - * Jelly uses reflection here and 'getDeploymentsThreads()' to get the data by the method and variable (matching) names - * publishedBuildsDetails = new CopyOnWriteArrayList<>(); private final Run build; @Deprecated @@ -49,11 +53,11 @@ public BuildInfoResultAction(Run build) { public BuildInfoResultAction(String artifactoryUrl, Run build, String buildName) { this(build); String buildNumber = BuildUniqueIdentifierHelper.getBuildNumber(build); - publishedBuildsDetails.add(createBuildInfoIdentifier(artifactoryUrl, buildName, buildNumber)); + publishedBuildsDetails.add(createBuildInfoIdentifier(artifactoryUrl, buildName, buildNumber, "", "")); } - public void addBuildInfoResults(String artifactoryUrl, Build buildInfo) { - publishedBuildsDetails.add(createBuildInfoIdentifier(artifactoryUrl, build, buildInfo)); + public void addBuildInfoResults(String artifactoryUrl, String platformUrl, Build buildInfo) { + publishedBuildsDetails.add(createBuildInfoIdentifier(artifactoryUrl, build, buildInfo, platformUrl)); } public Run getBuild() { @@ -79,16 +83,20 @@ public String getUrlName() { String buildName = BuildUniqueIdentifierHelper.getBuildNameConsiderOverride(artifactoryRedeployPublisher, build); return generateUrl(artifactoryRedeployPublisher.getArtifactoryName(), build, buildName); } else if (publishedBuildsDetails.size() == 1) { - return publishedBuildsDetails.get(0).getBuildInfoUrl(); + try { + return publishedBuildsDetails.get(0).getBuildInfoUrl(); + } catch (ParseException e) { + log.log(Level.WARNING, "could not create build info URL", e); + } } return "published_builds"; } - private PublishedBuildDetails createBuildInfoIdentifier(String artifactoryUrl, String buildName, String buildNumber) { - return new PublishedBuildDetails(artifactoryUrl, Util.rawEncode(buildName), Util.rawEncode(buildNumber)); + private PublishedBuildDetails createBuildInfoIdentifier(String artifactoryUrl, String buildName, String buildNumber, String platformUrl, String startedBuildTimestamp) { + return new PublishedBuildDetails(artifactoryUrl, Util.rawEncode(buildName), Util.rawEncode(buildNumber), platformUrl, startedBuildTimestamp); } - private PublishedBuildDetails createBuildInfoIdentifier(String artifactoryUrl, Run build, Build buildInfo) { + private PublishedBuildDetails createBuildInfoIdentifier(String artifactoryUrl, Run build, Build buildInfo, String platformUrl) { String buildName; String buildNumber; if (StringUtils.isNotEmpty(buildInfo.getName())) { @@ -101,12 +109,11 @@ private PublishedBuildDetails createBuildInfoIdentifier(String artifactoryUrl, R } else { buildNumber = BuildUniqueIdentifierHelper.getBuildNumber(build); } - return createBuildInfoIdentifier(artifactoryUrl, buildName, buildNumber); + return createBuildInfoIdentifier(artifactoryUrl, buildName, buildNumber, platformUrl, buildInfo.getStarted()); } private String generateUrl(String artifactoryUrl, Run build, String buildName) { - return artifactoryUrl + "/webapp/builds/" + Util.rawEncode(buildName) + "/" - + Util.rawEncode(BuildUniqueIdentifierHelper.getBuildNumber(build)); + return ArtifactoryBuildInfoClient.createBuildInfoUrl(artifactoryUrl, buildName, BuildUniqueIdentifierHelper.getBuildNumber(build)); } /** diff --git a/src/main/java/org/jfrog/hudson/JFrogPlatformInstance.java b/src/main/java/org/jfrog/hudson/JFrogPlatformInstance.java new file mode 100644 index 000000000..e1392c199 --- /dev/null +++ b/src/main/java/org/jfrog/hudson/JFrogPlatformInstance.java @@ -0,0 +1,127 @@ +package org.jfrog.hudson; + +import org.apache.commons.lang.StringUtils; +import org.kohsuke.stapler.DataBoundConstructor; + +import java.util.ArrayList; +import java.util.List; + + +/** + * Represents an instance of jenkins JFrog instance configuration page. + */ +public class JFrogPlatformInstance { + public static final int DEFAULT_CONNECTION_TIMEOUT = 300; // 5 Minutes + public static final int DEFAULT_DEPLOYMENT_THREADS_NUMBER = 3; + + private String url; + private String id; + private ArtifactoryServer artifactoryServer; + private CredentialsConfig deployerCredentialsConfig; + private CredentialsConfig resolverCredentialsConfig; + private final boolean bypassProxy; + private int timeout = DEFAULT_CONNECTION_TIMEOUT; + private Integer connectionRetry; + private Integer deploymentThreads; + + @DataBoundConstructor + public JFrogPlatformInstance(String instanceId, String url, String artifactoryUrl, CredentialsConfig deployerCredentialsConfig, + CredentialsConfig resolverCredentialsConfig, int timeout, boolean bypassProxy, Integer connectionRetry, Integer deploymentThreads) { + this.id = instanceId; + this.url = StringUtils.isNotEmpty(url) ? StringUtils.removeEnd(url, "/") : null; + this.deployerCredentialsConfig = deployerCredentialsConfig; + this.resolverCredentialsConfig = resolverCredentialsConfig; + this.timeout = timeout > 0 ? timeout : DEFAULT_CONNECTION_TIMEOUT; + this.bypassProxy = bypassProxy; + this.connectionRetry = connectionRetry != null ? connectionRetry : 3; + this.deploymentThreads = deploymentThreads != null && deploymentThreads > 0 ? deploymentThreads : DEFAULT_DEPLOYMENT_THREADS_NUMBER; + artifactoryServer = new ArtifactoryServer(this.id, artifactoryUrl, this.deployerCredentialsConfig, this.resolverCredentialsConfig, this.timeout, this.bypassProxy, this.connectionRetry, this.deploymentThreads); + } + + public JFrogPlatformInstance(ArtifactoryServer artifactoryServer) { + this(artifactoryServer.getServerId(), "", artifactoryServer.getArtifactoryUrl(), artifactoryServer.getDeployerCredentialsConfig(), artifactoryServer.getResolverCredentialsConfig(), artifactoryServer.getTimeout(), artifactoryServer.isBypassProxy(), artifactoryServer.getConnectionRetry(), artifactoryServer.getDeploymentThreads()); + } + + public JFrogPlatformInstance(org.jfrog.hudson.pipeline.common.types.ArtifactoryServer artifactoryServer) { + this("", "",artifactoryServer.getUrl(), artifactoryServer.createCredentialsConfig(), artifactoryServer.createCredentialsConfig(), artifactoryServer.getConnection().getTimeout(), artifactoryServer.isBypassProxy(), artifactoryServer.getConnection().getRetry(), artifactoryServer.getDeploymentThreads()); + } + + public String getId() { + return id; + } + + public String getUrl() { + return url; + } + + public ArtifactoryServer getArtifactoryServer() { + return artifactoryServer; + } + + public CredentialsConfig getDeployerCredentialsConfig() { + return deployerCredentialsConfig; + } + + public CredentialsConfig getResolverCredentialsConfig() { + return resolverCredentialsConfig; + } + + + // To populate the dropdown list from the jelly + public List getConnectionRetries() { + List items = new ArrayList(); + for (int i = 0; i < 10; i++) { + items.add(i); + } + return items; + } + + /** + * Return number of deployment threads. + * To populate the dropdown list from the jelly: + * + */ + @SuppressWarnings("unused") + public List getDeploymentsThreads() { + List items = new ArrayList<>(); + for (int i = 1; i <= 10; i++) { + items.add(i); + } + return items; + } + + public int getTimeout() { + return timeout; + } + + public boolean isBypassProxy() { + return bypassProxy; + } + + public int getConnectionRetry() { + if (connectionRetry == null) { + connectionRetry = 3; + } + return connectionRetry; + } + + public void setConnectionRetry(int connectionRetry) { + this.connectionRetry = connectionRetry; + } + + public Integer getDeploymentThreads() { + return deploymentThreads; + } + + /** + * Set the number of deployment threads. + * Jelly uses reflection here and 'getDeploymentsThreads()' to get the data by the method and variable (matching) names + * project) { diff --git a/src/main/java/org/jfrog/hudson/generic/ArtifactoryGenericConfigurator.java b/src/main/java/org/jfrog/hudson/generic/ArtifactoryGenericConfigurator.java index fafb59996..af9f03291 100644 --- a/src/main/java/org/jfrog/hudson/generic/ArtifactoryGenericConfigurator.java +++ b/src/main/java/org/jfrog/hudson/generic/ArtifactoryGenericConfigurator.java @@ -320,7 +320,7 @@ public ServerDetails getLegacyResolverDetails() { } public ArtifactoryServer getArtifactoryServer() { - return RepositoriesUtils.getArtifactoryServer(getArtifactoryName(), getDescriptor().getArtifactoryServers()); + return RepositoriesUtils.getArtifactoryServer(getArtifactoryName()); } public ArtifactoryServer getArtifactoryResolverServer() { @@ -329,8 +329,7 @@ public ArtifactoryServer getArtifactoryResolverServer() { throw new RuntimeException("Artifactory server for dependencies resolution is null"); } - ArtifactoryServer server = RepositoriesUtils.getArtifactoryServer(serverId, - getDescriptor().getArtifactoryServers()); + ArtifactoryServer server = RepositoriesUtils.getArtifactoryServer(serverId); if (server == null) { throw new RuntimeException(String.format("The job is configured to use an Artifactory server with ID '%s' for dependencies resolution. This server however does not exist", serverId)); } diff --git a/src/main/java/org/jfrog/hudson/gradle/ArtifactoryGradleConfigurator.java b/src/main/java/org/jfrog/hudson/gradle/ArtifactoryGradleConfigurator.java index 1e2e1e041..0d64d242f 100644 --- a/src/main/java/org/jfrog/hudson/gradle/ArtifactoryGradleConfigurator.java +++ b/src/main/java/org/jfrog/hudson/gradle/ArtifactoryGradleConfigurator.java @@ -620,12 +620,11 @@ private void setTargetsField(Gradle builder, String fieldName, String value) { } public ArtifactoryServer getArtifactoryServer() { - return RepositoriesUtils.getArtifactoryServer(getArtifactoryName(), getDescriptor().getArtifactoryServers()); + return RepositoriesUtils.getArtifactoryServer(getArtifactoryName()); } public ArtifactoryServer getArtifactoryResolverServer() { - return RepositoriesUtils.getArtifactoryServer(getArtifactoryResolverName(), - getDescriptor().getArtifactoryServers()); + return RepositoriesUtils.getArtifactoryServer(getArtifactoryResolverName()); } public List getReleaseRepositories() { diff --git a/src/main/java/org/jfrog/hudson/ivy/ArtifactoryIvyConfigurator.java b/src/main/java/org/jfrog/hudson/ivy/ArtifactoryIvyConfigurator.java index 3a31061ef..b98c1ace2 100644 --- a/src/main/java/org/jfrog/hudson/ivy/ArtifactoryIvyConfigurator.java +++ b/src/main/java/org/jfrog/hudson/ivy/ArtifactoryIvyConfigurator.java @@ -324,7 +324,7 @@ public String getAdditionalArgs() { } public ArtifactoryServer getArtifactoryServer() { - return RepositoriesUtils.getArtifactoryServer(getArtifactoryName(), getDescriptor().getArtifactoryServers()); + return RepositoriesUtils.getArtifactoryServer(getArtifactoryName()); } public List getReleaseRepositoryList() { diff --git a/src/main/java/org/jfrog/hudson/ivy/ArtifactoryIvyFreeStyleConfigurator.java b/src/main/java/org/jfrog/hudson/ivy/ArtifactoryIvyFreeStyleConfigurator.java index 39f07d136..6e144de50 100644 --- a/src/main/java/org/jfrog/hudson/ivy/ArtifactoryIvyFreeStyleConfigurator.java +++ b/src/main/java/org/jfrog/hudson/ivy/ArtifactoryIvyFreeStyleConfigurator.java @@ -422,7 +422,7 @@ private PublisherContext.Builder getBuilder() { } public ArtifactoryServer getArtifactoryServer() { - return RepositoriesUtils.getArtifactoryServer(getArtifactoryName(), getDescriptor().getArtifactoryServers()); + return RepositoriesUtils.getArtifactoryServer(getArtifactoryName()); } public List getReleaseRepositoryList() { diff --git a/src/main/java/org/jfrog/hudson/maven2/MavenBuildInfoDeployer.java b/src/main/java/org/jfrog/hudson/maven2/MavenBuildInfoDeployer.java index dd09a8d2a..ceb36c994 100644 --- a/src/main/java/org/jfrog/hudson/maven2/MavenBuildInfoDeployer.java +++ b/src/main/java/org/jfrog/hudson/maven2/MavenBuildInfoDeployer.java @@ -33,11 +33,9 @@ import org.jfrog.build.api.builder.DependencyBuilder; import org.jfrog.build.api.builder.ModuleBuilder; import org.jfrog.build.extractor.clientConfiguration.client.ArtifactoryBuildInfoClient; -import org.jfrog.hudson.AbstractBuildInfoDeployer; -import org.jfrog.hudson.BuildInfoAwareConfigurator; -import org.jfrog.hudson.MavenDependenciesRecord; -import org.jfrog.hudson.MavenDependency; +import org.jfrog.hudson.*; import org.jfrog.hudson.action.ActionableHelper; +import org.jfrog.hudson.util.RepositoriesUtils; import java.io.IOException; import java.util.List; @@ -64,8 +62,9 @@ public MavenBuildInfoDeployer(BuildInfoAwareConfigurator configurator, Artifacto public void deploy() throws IOException { String url = configurator.getArtifactoryServer().getArtifactoryUrl() + "/api/build"; + JFrogPlatformInstance jfrogServer = RepositoriesUtils.getJFrogPlatformInstances(configurator.getArtifactoryServer().getServerId()); listener.getLogger().println("Deploying build info to: " + url); - client.sendBuildInfo(buildInfo); + client.sendBuildInfo(buildInfo, jfrogServer.getUrl()); } private void gatherModuleAndDependencyInfo(MavenModuleSetBuild mavenModulesBuild) { diff --git a/src/main/java/org/jfrog/hudson/maven3/ArtifactoryMaven3Configurator.java b/src/main/java/org/jfrog/hudson/maven3/ArtifactoryMaven3Configurator.java index 94d42d9d2..41df08953 100644 --- a/src/main/java/org/jfrog/hudson/maven3/ArtifactoryMaven3Configurator.java +++ b/src/main/java/org/jfrog/hudson/maven3/ArtifactoryMaven3Configurator.java @@ -240,7 +240,7 @@ public boolean isRecordAllDependencies() { } public ArtifactoryServer getArtifactoryServer() { - return RepositoriesUtils.getArtifactoryServer(getArtifactoryName(), getDescriptor().getArtifactoryServers()); + return RepositoriesUtils.getArtifactoryServer(getArtifactoryName()); } @SuppressWarnings({"UnusedDeclaration"}) @@ -310,7 +310,7 @@ public boolean isMultiConfProject() { } public ArtifactoryServer getArtifactoryServer(String artifactoryServerName) { - return RepositoriesUtils.getArtifactoryServer(artifactoryServerName, getDescriptor().getArtifactoryServers()); + return RepositoriesUtils.getArtifactoryServer(artifactoryServerName); } public List getReleaseRepositoryList() { diff --git a/src/main/java/org/jfrog/hudson/maven3/ArtifactoryMaven3NativeConfigurator.java b/src/main/java/org/jfrog/hudson/maven3/ArtifactoryMaven3NativeConfigurator.java index 4d2512fea..10251c94f 100644 --- a/src/main/java/org/jfrog/hudson/maven3/ArtifactoryMaven3NativeConfigurator.java +++ b/src/main/java/org/jfrog/hudson/maven3/ArtifactoryMaven3NativeConfigurator.java @@ -130,10 +130,10 @@ public Environment setUp(final AbstractBuild build, Launcher launcher, BuildList } public ArtifactoryServer getArtifactoryServer() { - List servers = getDescriptor().getArtifactoryServers(); - for (ArtifactoryServer server : servers) { - if (server.getServerId().equals(getArtifactoryName())) { - return server; + List jfrogInstances = getDescriptor().getJfrogInstances(); + for (JFrogPlatformInstance JFrogPlatformInstance : jfrogInstances) { + if (JFrogPlatformInstance.getId().equals(getArtifactoryName())) { + return JFrogPlatformInstance.getArtifactoryServer(); } } return null; @@ -143,10 +143,10 @@ public List getVirtualRepositoryList() { String releaseRepoKey = getDeployerDetails().getResolveReleaseRepository().getKeyFromSelect(); String snapshotRepoKey = getDeployerDetails().getResolveSnapshotRepository().getKeyFromSelect(); - // Add the releases repo to the reposities list, in case it is not there: + // Add the releases repo to the repositories list, in case it is not there: List repos = RepositoriesUtils.collectVirtualRepositories(null, releaseRepoKey); - // Add the snapshots repo to the reposities list, in case it is not there: + // Add the snapshots repo to the repositories list, in case it is not there: return RepositoriesUtils.collectVirtualRepositories(repos, snapshotRepoKey); } diff --git a/src/main/java/org/jfrog/hudson/pipeline/common/BuildInfoDeployer.java b/src/main/java/org/jfrog/hudson/pipeline/common/BuildInfoDeployer.java index d7334ab3a..543a4360d 100644 --- a/src/main/java/org/jfrog/hudson/pipeline/common/BuildInfoDeployer.java +++ b/src/main/java/org/jfrog/hudson/pipeline/common/BuildInfoDeployer.java @@ -32,12 +32,14 @@ public class BuildInfoDeployer extends AbstractBuildInfoDeployer { private ArtifactoryConfigurator configurator; private Build buildInfo; private boolean asyncBuildRetention; + private final String platformUrl; public BuildInfoDeployer(ArtifactoryConfigurator configurator, ArtifactoryBuildInfoClient client, - Run build, TaskListener listener, BuildInfo deployedBuildInfo) throws IOException, InterruptedException, NoSuchAlgorithmException { + Run build, TaskListener listener, BuildInfo deployedBuildInfo, String platformUrl) throws IOException, InterruptedException, NoSuchAlgorithmException { super(configurator, build, listener, client); this.configurator = configurator; this.build = build; + this.platformUrl = platformUrl; envVars = deployedBuildInfo.getEnvVars(); sysVars = deployedBuildInfo.getSysVars(); buildInfo = createBuildInfo("Pipeline", ""); @@ -91,7 +93,7 @@ public void deploy() throws IOException { listener.getLogger().println("Deploying build info to: " + artifactoryUrl + "/api/build"); BuildRetention retention = buildInfo.getBuildRetention(); buildInfo.setBuildRetention(null); - org.jfrog.build.extractor.retention.Utils.sendBuildAndBuildRetention(client, this.buildInfo, retention, asyncBuildRetention); + org.jfrog.build.extractor.retention.Utils.sendBuildAndBuildRetention(client, this.buildInfo, retention, asyncBuildRetention, platformUrl); addBuildInfoResultAction(artifactoryUrl); } @@ -102,7 +104,7 @@ private void addBuildInfoResultAction(String artifactoryUrl) { action = new BuildInfoResultAction(build); build.addAction(action); } - action.addBuildInfoResults(artifactoryUrl, buildInfo); + action.addBuildInfoResults(artifactoryUrl, platformUrl, buildInfo); } } diff --git a/src/main/java/org/jfrog/hudson/pipeline/common/Utils.java b/src/main/java/org/jfrog/hudson/pipeline/common/Utils.java index a5f3525e3..167cc1aa5 100644 --- a/src/main/java/org/jfrog/hudson/pipeline/common/Utils.java +++ b/src/main/java/org/jfrog/hudson/pipeline/common/Utils.java @@ -130,7 +130,7 @@ public static org.jfrog.hudson.ArtifactoryServer prepareArtifactoryServer(String return new org.jfrog.hudson.ArtifactoryServer(null, pipelineServer.getUrl(), credentials, credentials, pipelineServer.getConnection().getTimeout(), pipelineServer.isBypassProxy(), pipelineServer.getConnection().getRetry(), pipelineServer.getDeploymentThreads()); } - return RepositoriesUtils.getArtifactoryServer(artifactoryServerID, RepositoriesUtils.getArtifactoryServers()); + return RepositoriesUtils.getArtifactoryServer(artifactoryServerID); } public static BuildInfo prepareBuildinfo(Run build, BuildInfo buildinfo) { diff --git a/src/main/java/org/jfrog/hudson/pipeline/common/executors/GetArtifactoryServerExecutor.java b/src/main/java/org/jfrog/hudson/pipeline/common/executors/GetArtifactoryServerExecutor.java deleted file mode 100644 index d4f96e799..000000000 --- a/src/main/java/org/jfrog/hudson/pipeline/common/executors/GetArtifactoryServerExecutor.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.jfrog.hudson.pipeline.common.executors; - -import hudson.model.Run; -import org.apache.commons.lang.StringUtils; -import org.jfrog.hudson.ArtifactoryServer; -import org.jfrog.hudson.util.Credentials; -import org.jfrog.hudson.util.RepositoriesUtils; -import org.jfrog.hudson.util.plugins.PluginsUtils; - -import java.util.ArrayList; -import java.util.List; - -public class GetArtifactoryServerExecutor implements Executor { - - private org.jfrog.hudson.pipeline.common.types.ArtifactoryServer artifactoryServer; - private final String artifactoryServerID; - private final Run build; - - public GetArtifactoryServerExecutor(Run build, String artifactoryServerID) { - this.artifactoryServerID = artifactoryServerID; - this.build = build; - } - - public org.jfrog.hudson.pipeline.common.types.ArtifactoryServer getArtifactoryServer() { - return artifactoryServer; - } - - @Override - public void execute() { - if (StringUtils.isEmpty(artifactoryServerID)) { - throw new ServerNotFoundException("Artifactory server name is mandatory"); - } - - List artifactoryServers = new ArrayList<>(); - List artifactoryConfiguredServers = RepositoriesUtils.getArtifactoryServers(); - if (artifactoryConfiguredServers == null) { - throw new ServerNotFoundException("No Artifactory servers were configured"); - } - for (ArtifactoryServer server : artifactoryConfiguredServers) { - if (server.getServerId().equals(artifactoryServerID)) { - artifactoryServers.add(server); - } - } - if (artifactoryServers.isEmpty()) { - throw new ServerNotFoundException("Couldn't find Artifactory server with ID: " + artifactoryServerID); - } - if (artifactoryServers.size() > 1) { - throw new ServerNotFoundException("Duplicate configured Artifactory server ID: " + artifactoryServerID); - } - ArtifactoryServer server = artifactoryServers.get(0); - artifactoryServer = new org.jfrog.hudson.pipeline.common.types.ArtifactoryServer(artifactoryServerID, server.getArtifactoryUrl(), server.getDeploymentThreads()); - if (PluginsUtils.isCredentialsPluginEnabled()) { - artifactoryServer.setCredentialsId(server.getResolvingCredentialsConfig().getCredentialsId()); - } else { - Credentials serverCredentials = server.getResolvingCredentialsConfig().provideCredentials(build.getParent()); - artifactoryServer.setUsername(serverCredentials.getUsername()); - artifactoryServer.setPassword(serverCredentials.getPassword()); - } - artifactoryServer.setBypassProxy(server.isBypassProxy()); - artifactoryServer.getConnection().setRetry(server.getConnectionRetry()); - artifactoryServer.getConnection().setTimeout(server.getTimeout()); - } - - public static class ServerNotFoundException extends RuntimeException { - public ServerNotFoundException(String message) { - super(message); - } - } -} diff --git a/src/main/java/org/jfrog/hudson/pipeline/common/executors/GetJFrogPlatformInstancesExecutor.java b/src/main/java/org/jfrog/hudson/pipeline/common/executors/GetJFrogPlatformInstancesExecutor.java new file mode 100644 index 000000000..5f1fa2c44 --- /dev/null +++ b/src/main/java/org/jfrog/hudson/pipeline/common/executors/GetJFrogPlatformInstancesExecutor.java @@ -0,0 +1,59 @@ +package org.jfrog.hudson.pipeline.common.executors; + +import hudson.model.Run; +import org.apache.commons.lang.StringUtils; +import org.jfrog.hudson.JFrogPlatformInstance; +import org.jfrog.hudson.pipeline.common.types.ArtifactoryServer; +import org.jfrog.hudson.util.RepositoriesUtils; + +import java.util.ArrayList; +import java.util.List; + +public class GetJFrogPlatformInstancesExecutor implements Executor { + + private final String jfrogServersID; + private final Run build; + private org.jfrog.hudson.pipeline.common.types.JFrogPlatformInstance JFrogPlatformInstance; + + public GetJFrogPlatformInstancesExecutor(Run build, String jfrogServersID) { + this.jfrogServersID = jfrogServersID; + this.build = build; + } + + public org.jfrog.hudson.pipeline.common.types.JFrogPlatformInstance getJFrogPlatformInstance() { + return JFrogPlatformInstance; + } + + @Override + public void execute() { + if (StringUtils.isEmpty(jfrogServersID)) { + throw new ServerNotFoundException("JFrog Instance ID is mandatory"); + } + List jfrogInstancesFound = new ArrayList<>(); + List jfrogInstances = RepositoriesUtils.getJFrogPlatformInstances(); + if (jfrogInstances == null) { + throw new ServerNotFoundException("No JFrog Instances were configured"); + } + for (JFrogPlatformInstance instance : jfrogInstances) { + if (instance.getId().equals(jfrogServersID)) { + jfrogInstancesFound.add(instance); + } + } + if (jfrogInstancesFound.isEmpty()) { + throw new ServerNotFoundException("Couldn't find JFrog Instance ID: " + jfrogServersID); + } + if (jfrogInstancesFound.size() > 1) { + throw new ServerNotFoundException("Duplicate configured JFrog instance ID: " + jfrogServersID); + } + JFrogPlatformInstance JFrogPlatformInstance = jfrogInstancesFound.get(0); + ArtifactoryServer artifactoryServer = new ArtifactoryServer(JFrogPlatformInstance.getArtifactoryServer(), build.getParent()); + this.JFrogPlatformInstance = new org.jfrog.hudson.pipeline.common.types.JFrogPlatformInstance(artifactoryServer, JFrogPlatformInstance.getUrl(), JFrogPlatformInstance.getId()); + artifactoryServer.setJfrogServers(this.JFrogPlatformInstance); + } + + public static class ServerNotFoundException extends RuntimeException { + public ServerNotFoundException(String message) { + super(message); + } + } +} diff --git a/src/main/java/org/jfrog/hudson/pipeline/common/executors/PublishBuildInfoExecutor.java b/src/main/java/org/jfrog/hudson/pipeline/common/executors/PublishBuildInfoExecutor.java index 82e09605d..1ae817d28 100644 --- a/src/main/java/org/jfrog/hudson/pipeline/common/executors/PublishBuildInfoExecutor.java +++ b/src/main/java/org/jfrog/hudson/pipeline/common/executors/PublishBuildInfoExecutor.java @@ -34,8 +34,9 @@ public void execute() throws Exception { buildInfo.filterVariables(); buildInfo.appendVcs(Utils.extractVcs(ws, new JenkinsBuildInfoLog(listener))); org.jfrog.hudson.ArtifactoryServer server = Utils.prepareArtifactoryServer(null, pipelineServer); + String platformUrl = pipelineServer.getJfrogServers() != null ? pipelineServer.getJfrogServers().getUrl() : null; try (ArtifactoryBuildInfoClient client = this.createArtifactoryClient(server, build, listener)) { - buildInfo.createDeployer(build, listener, new ArtifactoryConfigurator(server), client).deploy(); + buildInfo.createDeployer(build, listener, new ArtifactoryConfigurator(server), client, platformUrl).deploy(); } } diff --git a/src/main/java/org/jfrog/hudson/pipeline/common/types/ArtifactoryServer.java b/src/main/java/org/jfrog/hudson/pipeline/common/types/ArtifactoryServer.java index e05843034..f53c97fa7 100644 --- a/src/main/java/org/jfrog/hudson/pipeline/common/types/ArtifactoryServer.java +++ b/src/main/java/org/jfrog/hudson/pipeline/common/types/ArtifactoryServer.java @@ -1,11 +1,14 @@ package org.jfrog.hudson.pipeline.common.types; import com.google.common.collect.Maps; +import hudson.model.Item; import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted; import org.jenkinsci.plugins.workflow.cps.CpsScript; import org.jfrog.hudson.CredentialsConfig; import org.jfrog.hudson.pipeline.common.Utils; import org.jfrog.hudson.pipeline.common.types.buildInfo.BuildInfo; +import org.jfrog.hudson.util.Credentials; +import org.jfrog.hudson.util.plugins.PluginsUtils; import java.io.Serializable; import java.util.ArrayList; @@ -19,6 +22,7 @@ /** * Created by romang on 4/21/16. + * Represents an instance of Artifactory configuration from pipeline script. */ public class ArtifactoryServer implements Serializable { public static final long serialVersionUID = 1L; @@ -43,6 +47,7 @@ public class ArtifactoryServer implements Serializable { private boolean usesCredentialsId; private final Connection connection = new Connection(); private int deploymentThreads; + private JFrogPlatformInstance JFrogPlatformInstance; public ArtifactoryServer() { } @@ -66,6 +71,22 @@ public ArtifactoryServer(String url, String credentialsId) { this.usesCredentialsId = true; } + public ArtifactoryServer(org.jfrog.hudson.ArtifactoryServer jenkinsArtifactoryServer, Item parent) { + serverName = jenkinsArtifactoryServer.getServerId(); + url = jenkinsArtifactoryServer.getArtifactoryUrl(); + this.deploymentThreads = jenkinsArtifactoryServer.getDeploymentThreads(); + if (PluginsUtils.isCredentialsPluginEnabled()) { + credentialsId = jenkinsArtifactoryServer.getResolvingCredentialsConfig().getCredentialsId(); + } else { + Credentials serverCredentials = jenkinsArtifactoryServer.getResolvingCredentialsConfig().provideCredentials(parent); + username = serverCredentials.getUsername(); + password = serverCredentials.getPassword(); + } + bypassProxy = jenkinsArtifactoryServer.isBypassProxy(); + connection.setRetry(jenkinsArtifactoryServer.getConnectionRetry()); + connection.setTimeout(jenkinsArtifactoryServer.getTimeout()); + } + public CredentialsConfig createCredentialsConfig() { CredentialsConfig credentialsConfig = new CredentialsConfig(this.username, this.password, this.credentialsId, null); credentialsConfig.setIgnoreCredentialPluginDisabled(usesCredentialsId); @@ -360,4 +381,12 @@ public int getDeploymentThreads() { public void setDeploymentThreads(int deploymentThreads) { this.deploymentThreads = deploymentThreads; } + + public JFrogPlatformInstance getJfrogServers() { + return JFrogPlatformInstance; + } + + public void setJfrogServers(JFrogPlatformInstance JFrogPlatformInstance) { + this.JFrogPlatformInstance = JFrogPlatformInstance; + } } diff --git a/src/main/java/org/jfrog/hudson/pipeline/common/types/JFrogPlatformInstance.java b/src/main/java/org/jfrog/hudson/pipeline/common/types/JFrogPlatformInstance.java new file mode 100644 index 000000000..78e2898ce --- /dev/null +++ b/src/main/java/org/jfrog/hudson/pipeline/common/types/JFrogPlatformInstance.java @@ -0,0 +1,46 @@ +package org.jfrog.hudson.pipeline.common.types; + +import org.apache.commons.lang.StringUtils; +import org.jenkinsci.plugins.workflow.cps.CpsScript; + +import java.io.Serializable; + +/** + * Represents an instance of jfrog server instance from pipeline script. + */ +public class JFrogPlatformInstance implements Serializable { + private final ArtifactoryServer artifactoryServer; + private String id; + private String url; + private CpsScript cpsScript; + + public JFrogPlatformInstance(ArtifactoryServer artifactoryServer, String url, String id) { + this.id = id; + this.url = StringUtils.removeEnd(url, "/"); + this.artifactoryServer = artifactoryServer; + } + + public ArtifactoryServer getArtifactoryServer() { + return artifactoryServer; + } + + public void setCpsScript(CpsScript cpsScript) { + this.cpsScript = cpsScript; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } +} diff --git a/src/main/java/org/jfrog/hudson/pipeline/common/types/buildInfo/BuildInfo.java b/src/main/java/org/jfrog/hudson/pipeline/common/types/buildInfo/BuildInfo.java index 696471837..b56eec44d 100644 --- a/src/main/java/org/jfrog/hudson/pipeline/common/types/buildInfo/BuildInfo.java +++ b/src/main/java/org/jfrog/hudson/pipeline/common/types/buildInfo/BuildInfo.java @@ -11,22 +11,17 @@ import org.apache.commons.lang.StringUtils; import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted; import org.jenkinsci.plugins.workflow.cps.CpsScript; -import org.jfrog.build.api.*; import org.jfrog.build.api.Module; +import org.jfrog.build.api.*; import org.jfrog.build.api.builder.BuildInfoBuilder; import org.jfrog.build.api.builder.ModuleBuilder; import org.jfrog.build.client.DeployableArtifactDetail; import org.jfrog.build.extractor.clientConfiguration.client.ArtifactoryBuildInfoClient; import org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails; import org.jfrog.build.extractor.clientConfiguration.deploy.DeployableArtifactsUtils; -import org.jfrog.hudson.ArtifactoryServer; -import org.jfrog.hudson.CredentialsConfig; import org.jfrog.hudson.pipeline.common.ArtifactoryConfigurator; import org.jfrog.hudson.pipeline.common.BuildInfoDeployer; import org.jfrog.hudson.util.BuildUniqueIdentifierHelper; -import org.jfrog.hudson.util.CredentialManager; -import org.jfrog.hudson.util.JenkinsBuildInfoLog; -import org.jfrog.hudson.util.ProxyUtils; import java.io.File; import java.io.IOException; @@ -247,9 +242,9 @@ public org.jfrog.build.api.Issues getConvertedIssues() { return this.issues.convertFromPipelineIssues(); } - public BuildInfoDeployer createDeployer(Run build, TaskListener listener, ArtifactoryConfigurator config, ArtifactoryBuildInfoClient client) + public BuildInfoDeployer createDeployer(Run build, TaskListener listener, ArtifactoryConfigurator config, ArtifactoryBuildInfoClient client, String platformUrl) throws InterruptedException, NoSuchAlgorithmException, IOException { - return new BuildInfoDeployer(config, client, build, listener, this); + return new BuildInfoDeployer(config, client, build, listener, this, platformUrl); } public void setCpsScript(CpsScript cpsScript) { diff --git a/src/main/java/org/jfrog/hudson/pipeline/declarative/utils/DeclarativePipelineUtils.java b/src/main/java/org/jfrog/hudson/pipeline/declarative/utils/DeclarativePipelineUtils.java index 95c04604c..a2da2c921 100644 --- a/src/main/java/org/jfrog/hudson/pipeline/declarative/utils/DeclarativePipelineUtils.java +++ b/src/main/java/org/jfrog/hudson/pipeline/declarative/utils/DeclarativePipelineUtils.java @@ -10,7 +10,7 @@ import org.apache.commons.lang.StringUtils; import org.jfrog.build.api.util.Log; import org.jfrog.hudson.pipeline.common.Utils; -import org.jfrog.hudson.pipeline.common.executors.GetArtifactoryServerExecutor; +import org.jfrog.hudson.pipeline.common.executors.GetJFrogPlatformInstancesExecutor; import org.jfrog.hudson.pipeline.common.types.ArtifactoryServer; import org.jfrog.hudson.pipeline.common.types.ConanClient; import org.jfrog.hudson.pipeline.common.types.buildInfo.BuildInfo; @@ -64,30 +64,31 @@ static String getBuildDataFileName(String stepName, String stepId) { } /** - * Get Artifactory server from global server configuration or from previous rtServer{...} scope. + * Get Artifactory server from global jfrog instances configuration or from previous rtServer{...} scope. * * @param build - Step's build. * @param rootWs - Step's root workspace. - * @param serverId - The server id. Can be defined from global server configuration or from previous rtServer{...} scope. + * @param id - The Artifactory server id. Can be defined from global jfrog instances configuration or from previous rtServer{...} scope. * @param throwIfMissing - Throw exception if server is missing. * @return Artifactory server. */ - public static ArtifactoryServer getArtifactoryServer(Run build, FilePath rootWs, String serverId, boolean throwIfMissing) throws IOException, InterruptedException { + public static ArtifactoryServer getArtifactoryServer(Run build, FilePath rootWs, String id, boolean throwIfMissing) throws IOException, InterruptedException { String buildNumber = BuildUniqueIdentifierHelper.getBuildNumber(build); - BuildDataFile buildDataFile = readBuildDataFile(rootWs, buildNumber, CreateServerStep.STEP_NAME, serverId); + BuildDataFile buildDataFile = readBuildDataFile(rootWs, buildNumber, CreateServerStep.STEP_NAME, id); // 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, serverId); + GetJFrogPlatformInstancesExecutor getJFrogPlatformInstancesExecutor = new GetJFrogPlatformInstancesExecutor(build, id); try { - getArtifactoryServerExecutor.execute(); - } catch (GetArtifactoryServerExecutor.ServerNotFoundException serverNotFound) { + getJFrogPlatformInstancesExecutor.execute(); + } catch (GetJFrogPlatformInstancesExecutor.ServerNotFoundException serverNotFound) { if (throwIfMissing) { throw serverNotFound; } + return null; } - return getArtifactoryServerExecutor.getArtifactoryServer(); + return getJFrogPlatformInstancesExecutor.getJFrogPlatformInstance().getArtifactoryServer(); } JsonNode jsonNode = buildDataFile.get(CreateServerStep.STEP_NAME); ArtifactoryServer server = createMapper().treeToValue(jsonNode, ArtifactoryServer.class); diff --git a/src/main/java/org/jfrog/hudson/pipeline/scripted/dsl/JfrogDSL.java b/src/main/java/org/jfrog/hudson/pipeline/scripted/dsl/JfrogDSL.java new file mode 100644 index 000000000..786c6f649 --- /dev/null +++ b/src/main/java/org/jfrog/hudson/pipeline/scripted/dsl/JfrogDSL.java @@ -0,0 +1,31 @@ +package org.jfrog.hudson.pipeline.scripted.dsl; + +import groovy.lang.Binding; +import hudson.Extension; +import org.jenkinsci.plugins.workflow.cps.CpsScript; +import org.jenkinsci.plugins.workflow.cps.GlobalVariable; + +import javax.annotation.Nonnull; + +@Extension +public class JfrogDSL extends GlobalVariable { + @Nonnull + @Override + public String getName() { + return "Jfrog"; + } + + @Nonnull + @Override + public Object getValue(@Nonnull CpsScript cpsScript) throws Exception { + Binding binding = cpsScript.getBinding(); + Object jfrog; + if (binding.hasVariable(getName())) { + jfrog = binding.getVariable(getName()); + } else { + jfrog = new JfrogPipelineGlobal(cpsScript); + binding.setVariable(getName(), jfrog); + } + return jfrog; + } +} diff --git a/src/main/java/org/jfrog/hudson/pipeline/scripted/dsl/JfrogPipelineGlobal.java b/src/main/java/org/jfrog/hudson/pipeline/scripted/dsl/JfrogPipelineGlobal.java new file mode 100644 index 000000000..cc243f61b --- /dev/null +++ b/src/main/java/org/jfrog/hudson/pipeline/scripted/dsl/JfrogPipelineGlobal.java @@ -0,0 +1,34 @@ +package org.jfrog.hudson.pipeline.scripted.dsl; + +import com.google.common.collect.Maps; +import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted; +import org.jenkinsci.plugins.workflow.cps.CpsScript; +import org.jfrog.hudson.pipeline.common.types.ArtifactoryServer; +import org.jfrog.hudson.pipeline.common.types.JFrogPlatformInstance; + +import java.io.Serializable; +import java.util.Map; + +public class JfrogPipelineGlobal implements Serializable { + private final CpsScript cpsScript; + private JFrogPlatformInstance JFrogPlatformInstance; + + public JfrogPipelineGlobal(CpsScript script) { + this.cpsScript = script; + } + + @Whitelisted + public JfrogPipelineGlobal instance(String instanceId) { + Map stepVariables = Maps.newLinkedHashMap(); + stepVariables.put("jfrogServersID", instanceId); + JFrogPlatformInstance = (JFrogPlatformInstance) cpsScript.invokeMethod("getJfrogServers", stepVariables); + JFrogPlatformInstance.setCpsScript(cpsScript); + JFrogPlatformInstance.getArtifactoryServer().setCpsScript(cpsScript); + return this; + } + + @Whitelisted + public ArtifactoryServer artifactory() { + return JFrogPlatformInstance.getArtifactoryServer(); + } +} diff --git a/src/main/java/org/jfrog/hudson/pipeline/scripted/steps/GetArtifactoryServerStep.java b/src/main/java/org/jfrog/hudson/pipeline/scripted/steps/GetArtifactoryServerStep.java index 35b833186..481b525a8 100644 --- a/src/main/java/org/jfrog/hudson/pipeline/scripted/steps/GetArtifactoryServerStep.java +++ b/src/main/java/org/jfrog/hudson/pipeline/scripted/steps/GetArtifactoryServerStep.java @@ -7,7 +7,7 @@ import org.jenkinsci.plugins.workflow.steps.StepContext; import org.jfrog.hudson.pipeline.ArtifactorySynchronousStepExecution; import org.jfrog.hudson.pipeline.common.Utils; -import org.jfrog.hudson.pipeline.common.executors.GetArtifactoryServerExecutor; +import org.jfrog.hudson.pipeline.common.executors.GetJFrogPlatformInstancesExecutor; import org.jfrog.hudson.pipeline.common.types.ArtifactoryServer; import org.kohsuke.stapler.DataBoundConstructor; @@ -19,7 +19,7 @@ public class GetArtifactoryServerStep extends AbstractStepImpl { static final String STEP_NAME = "getArtifactoryServer"; private final String artifactoryServerID; - private org.jfrog.hudson.pipeline.common.types.ArtifactoryServer artifactoryServer; + private ArtifactoryServer artifactoryServer; @DataBoundConstructor public GetArtifactoryServerStep(String artifactoryServerID) { @@ -41,11 +41,12 @@ public Execution(GetArtifactoryServerStep step, StepContext context) throws IOEx } @Override - protected org.jfrog.hudson.pipeline.common.types.ArtifactoryServer runStep() throws Exception { + protected ArtifactoryServer runStep() throws Exception { String artifactoryServerID = step.getArtifactoryServerID(); - GetArtifactoryServerExecutor getArtifactoryServerExecutor = new GetArtifactoryServerExecutor(build, artifactoryServerID); - getArtifactoryServerExecutor.execute(); - step.artifactoryServer = getArtifactoryServerExecutor.getArtifactoryServer(); + // jfrogServersID is the same as its Artifactory Server ID + GetJFrogPlatformInstancesExecutor getJFrogPlatformInstancesExecutor = new GetJFrogPlatformInstancesExecutor(build, artifactoryServerID); + getJFrogPlatformInstancesExecutor.execute(); + step.artifactoryServer = getJFrogPlatformInstancesExecutor.getJFrogPlatformInstance().getArtifactoryServer(); return step.artifactoryServer; } diff --git a/src/main/java/org/jfrog/hudson/pipeline/scripted/steps/GetJfrogServersStep.java b/src/main/java/org/jfrog/hudson/pipeline/scripted/steps/GetJfrogServersStep.java new file mode 100644 index 000000000..ccdd260ce --- /dev/null +++ b/src/main/java/org/jfrog/hudson/pipeline/scripted/steps/GetJfrogServersStep.java @@ -0,0 +1,85 @@ +package org.jfrog.hudson.pipeline.scripted.steps; + +import com.google.inject.Inject; +import hudson.Extension; +import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl; +import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl; +import org.jenkinsci.plugins.workflow.steps.StepContext; +import org.jfrog.hudson.ArtifactoryServer; +import org.jfrog.hudson.pipeline.ArtifactorySynchronousStepExecution; +import org.jfrog.hudson.pipeline.common.Utils; +import org.jfrog.hudson.pipeline.common.executors.GetJFrogPlatformInstancesExecutor; +import org.jfrog.hudson.pipeline.common.types.JFrogPlatformInstance; +import org.kohsuke.stapler.DataBoundConstructor; + +import java.io.IOException; + +public class GetJfrogServersStep extends AbstractStepImpl { + static final String STEP_NAME = "getJFrogPlatformInstance"; + private final String JFrogPlatformInstanceID; + private JFrogPlatformInstance JFrogPlatformInstance; + + @DataBoundConstructor + public GetJfrogServersStep(String JFrogPlatformInstanceID) { + this.JFrogPlatformInstanceID = JFrogPlatformInstanceID; + } + + private String getJFrogPlatformInstanceID() { + return JFrogPlatformInstanceID; + } + + public static class Execution extends ArtifactorySynchronousStepExecution { + + private transient final GetJfrogServersStep step; + + @Inject + public Execution(GetJfrogServersStep step, StepContext context) throws IOException, InterruptedException { + super(context); + this.step = step; + } + + @Override + protected JFrogPlatformInstance runStep() throws Exception { + String JFrogPlatformInstanceID = step.getJFrogPlatformInstanceID(); + GetJFrogPlatformInstancesExecutor getArtifactoryServerExecutor = new GetJFrogPlatformInstancesExecutor(build, JFrogPlatformInstanceID); + getArtifactoryServerExecutor.execute(); + step.JFrogPlatformInstance = getArtifactoryServerExecutor.getJFrogPlatformInstance(); + return step.JFrogPlatformInstance; + } + + @Override + public ArtifactoryServer getUsageReportServer() { + return Utils.prepareArtifactoryServer(step.getJFrogPlatformInstanceID(), null); + } + + @Override + public String getUsageReportFeatureName() { + return STEP_NAME; + } + } + + @Extension + public static final class DescriptorImpl extends AbstractStepDescriptorImpl { + + public DescriptorImpl() { + super(Execution.class); + } + + @Override + public String getFunctionName() { + return STEP_NAME; + } + + @Override + public String getDisplayName() { + return "Get Jfrog servers from Jenkins config"; + } + + @Override + public boolean isAdvanced() { + return true; + } + } +} + + diff --git a/src/main/java/org/jfrog/hudson/trigger/ArtifactoryTrigger.java b/src/main/java/org/jfrog/hudson/trigger/ArtifactoryTrigger.java index f987ade0c..61ea6c5a2 100644 --- a/src/main/java/org/jfrog/hudson/trigger/ArtifactoryTrigger.java +++ b/src/main/java/org/jfrog/hudson/trigger/ArtifactoryTrigger.java @@ -11,6 +11,7 @@ import org.jfrog.build.client.ItemLastModified; import org.jfrog.build.extractor.clientConfiguration.client.ArtifactoryBuildInfoClient; import org.jfrog.hudson.ArtifactoryServer; +import org.jfrog.hudson.JFrogPlatformInstance; import org.jfrog.hudson.ServerDetails; import org.jfrog.hudson.util.JenkinsBuildInfoLog; import org.jfrog.hudson.util.ProxyUtils; @@ -114,13 +115,13 @@ private ArtifactoryServer getArtifactoryServerFromPipeline() { } /** - * Get Artifactory server from the global configuration by server ID. Throw RuntimeException if not exist. + * Get Artifactory server from the Jfrog Instances configuration by server ID. Throw RuntimeException if not exist. * * @param serverId - The server ID to look * @return artifactory server */ private ArtifactoryServer getGlobalArtifactoryServer(String serverId) { - ArtifactoryServer server = RepositoriesUtils.getArtifactoryServer(serverId, RepositoriesUtils.getArtifactoryServers()); + ArtifactoryServer server = RepositoriesUtils.getArtifactoryServer(serverId); if (server == null) { handleServerNotExist(serverId); } @@ -152,18 +153,18 @@ public String getSelectedServerId() { } /** - * Get a list of Artifactory servers. Used in the Jelly to show the available servers to select. + * Get a list of Jfrog instances. Used in the Jelly to show the available servers to select. * If applicable, show the server selected in the pipeline. * * @return a list of Artifactory servers */ - public List getArtifactoryServers() { - List servers = new ArrayList<>(RepositoriesUtils.getArtifactoryServers()); + public List getJfrogInstances() { + List jfrogInstances = new ArrayList<>(RepositoriesUtils.getJFrogPlatformInstances()); ArtifactoryServer propertyServer = getArtifactoryServerFromPipeline(); if (propertyServer != null) { - servers.add(propertyServer); + jfrogInstances.add(new JFrogPlatformInstance(propertyServer)); } - return servers; + return jfrogInstances; } @Override @@ -188,8 +189,8 @@ public boolean isApplicable(Item item) { * * @return a list of Artifactory servers */ - public List getArtifactoryServers() { - return RepositoriesUtils.getArtifactoryServers(); + public List getJfrogInstances() { + return RepositoriesUtils.getJFrogPlatformInstances(); } } } \ No newline at end of file diff --git a/src/main/java/org/jfrog/hudson/util/RepositoriesUtils.java b/src/main/java/org/jfrog/hudson/util/RepositoriesUtils.java index 4a806f78f..3116fdd1b 100644 --- a/src/main/java/org/jfrog/hudson/util/RepositoriesUtils.java +++ b/src/main/java/org/jfrog/hudson/util/RepositoriesUtils.java @@ -2,7 +2,10 @@ import com.google.common.base.Function; import com.google.common.collect.Lists; -import hudson.model.*; +import hudson.model.AbstractBuild; +import hudson.model.BuildListener; +import hudson.model.Hudson; +import hudson.model.Item; import jenkins.model.Jenkins; import org.apache.commons.lang.StringUtils; import org.jfrog.build.api.util.NullLog; @@ -115,11 +118,32 @@ public static List getLocalRepositories(String url, CredentialsConfig cr } } - public static ArtifactoryServer getArtifactoryServer(String artifactoryIdentity, List artifactoryServers) { - if (artifactoryServers != null) { - for (ArtifactoryServer server : artifactoryServers) { - if (server.getArtifactoryUrl().equals(artifactoryIdentity) || server.getServerId().equals(artifactoryIdentity)) { - return server; + /** + * Search for Artifactory server by `key` (could be Artifactory server URL or serverId). + * + * @param key - The key on which to do a search. + * @return - ArtifactoryServer + */ + public static ArtifactoryServer getArtifactoryServer(String key) { + JFrogPlatformInstance JFrogPlatformInstance = getJFrogPlatformInstances(key); + if (JFrogPlatformInstance != null) { + return JFrogPlatformInstance.getArtifactoryServer(); + } + return null; + } + + /** + * Search for Jfrog instance by `key` (could be Artifactory server URL or serverId). + * + * @param key - The key on which to do a search. + * @return - JFrogPlatformInstance + */ + public static JFrogPlatformInstance getJFrogPlatformInstances(String key) { + List jfrogInstances = getJFrogPlatformInstances(); + if (jfrogInstances != null && jfrogInstances.size() > 0) { + for (JFrogPlatformInstance JFrogPlatformInstance : jfrogInstances) { + if (JFrogPlatformInstance.getArtifactoryServer().getArtifactoryUrl().equals(key) || JFrogPlatformInstance.getArtifactoryServer().getServerId().equals(key)) { + return JFrogPlatformInstance; } } } @@ -127,14 +151,14 @@ public static ArtifactoryServer getArtifactoryServer(String artifactoryIdentity, } /** - * Returns the list of {@link org.jfrog.hudson.ArtifactoryServer} configured. + * Returns the list of {@link JFrogPlatformInstance} configured. * * @return can be empty but never null. */ - public static List getArtifactoryServers() { + public static List getJFrogPlatformInstances() { ArtifactoryBuilder.DescriptorImpl descriptor = (ArtifactoryBuilder.DescriptorImpl) Hudson.get().getDescriptor(ArtifactoryBuilder.class); - return descriptor.getArtifactoryServers(); + return descriptor.getJfrogInstances(); } public static List createRepositoriesList(List repositoriesValueList) { diff --git a/src/main/java/org/jfrog/hudson/util/converters/ArtifactoryBuilderConverter.java b/src/main/java/org/jfrog/hudson/util/converters/ArtifactoryBuilderConverter.java new file mode 100644 index 000000000..1deacb138 --- /dev/null +++ b/src/main/java/org/jfrog/hudson/util/converters/ArtifactoryBuilderConverter.java @@ -0,0 +1,63 @@ +package org.jfrog.hudson.util.converters; + +import com.google.common.collect.Lists; +import com.thoughtworks.xstream.converters.UnmarshallingContext; +import hudson.util.XStream2; +import org.jfrog.hudson.ArtifactoryBuilder; +import org.jfrog.hudson.ArtifactoryServer; +import org.jfrog.hudson.JFrogPlatformInstance; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +public class ArtifactoryBuilderConverter extends XStream2.PassthruConverter { + Logger logger = Logger.getLogger(ArtifactoryBuilderConverter.class.getName()); + List converterErrors = Lists.newArrayList(); + + public ArtifactoryBuilderConverter(XStream2 xstream) { + super(xstream); + } + + @Override + protected void callback(ArtifactoryBuilder.DescriptorImpl artifactoryBuilder, UnmarshallingContext unmarshallingContext) { + jfrogPlatformMigration(artifactoryBuilder); + if (!converterErrors.isEmpty()) { + logger.info(converterErrors.toString()); + } + } + + private void jfrogPlatformMigration(ArtifactoryBuilder.DescriptorImpl artifactoryBuilder) { + Class overriderClass = artifactoryBuilder.getClass(); + Field artifactoryServersField = null; + try { + artifactoryServersField = overriderClass.getDeclaredField("artifactoryServers"); + Field jfrogInstancesField = overriderClass.getDeclaredField("jfrogInstances"); + artifactoryServersField.setAccessible(true); + jfrogInstancesField.setAccessible(true); + + Object artifactoryServersObj = artifactoryServersField.get(artifactoryBuilder); + Object jfrogServersObj = jfrogInstancesField.get(artifactoryBuilder); + + if (artifactoryServersObj != null && jfrogServersObj == null) { + List artifactoryServers = (List) artifactoryServersObj; + // Must not be null. + // Once the artifactory builder will get save in the new form(jfrog instances), it is no longer needed to do a conversion. + // In order to identify if a conversion has already made for the first time, we validate if 'jfrogInstances' is found. + List jfrogInstances = new ArrayList<>(); + for (ArtifactoryServer artifactoryServer : artifactoryServers) { + jfrogInstances.add(new JFrogPlatformInstance(artifactoryServer)); + } + jfrogInstancesField.set(artifactoryBuilder, jfrogInstances); + } + } catch (IllegalAccessException | NoSuchFieldException e) { + converterErrors.add(getConversionErrorMessage(artifactoryBuilder, e)); + } + } + + private String getConversionErrorMessage(ArtifactoryBuilder.DescriptorImpl artifactoryBuilder, Exception e) { + return String.format("Could not convert the class '%s' to use the new overriding" + + "format. Cause: %s", artifactoryBuilder.getClass().getName(), e.getCause()); + } +} diff --git a/src/main/resources/lib/jfrog/global/global.js b/src/main/resources/lib/jfrog/global/global.js index a9c2693b2..1a6843f9b 100644 --- a/src/main/resources/lib/jfrog/global/global.js +++ b/src/main/resources/lib/jfrog/global/global.js @@ -5,8 +5,8 @@ function populateDropDownList() { const DEFAULT_OPTIONS_NUMBER = 10; - let artifactoryServers = document.getElementsByName("artifactoryServer"); - let t = document.getElementsByName("artifactoryServer")[artifactoryServers.length - 1]; + let jfrogInstances = document.getElementsByName("jfrogInstances"); + let t = document.getElementsByName("jfrogInstances")[jfrogInstances.length - 1]; let button = t.nextElementSibling.nextElementSibling; button.onclick = function () { @@ -27,7 +27,7 @@ function populateDropDownList() { } // Populates the timeout field - let timeout = document.getElementsByName("_.artifactory.timeout"); + let timeout = document.getElementsByName("_.instance.timeout"); let value = 300; for (let i = 0; i < timeout.length; i++) { if (!timeout[i].value) { diff --git a/src/main/resources/org/jfrog/hudson/ArtifactoryBuilder/global.jelly b/src/main/resources/org/jfrog/hudson/ArtifactoryBuilder/global.jelly index 95e7356ed..1e3d079bc 100644 --- a/src/main/resources/org/jfrog/hudson/ArtifactoryBuilder/global.jelly +++ b/src/main/resources/org/jfrog/hudson/ArtifactoryBuilder/global.jelly @@ -15,73 +15,81 @@ field="useCredentialsPlugin" title="${%Use the Credentials Plugin}"/> - + - - + + - - + + - - + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - + - + - + + value="${instance.deployerCredentialsConfig.username}"/> + value="${instance.deployerCredentialsConfig.password}"/> @@ -89,33 +97,35 @@ + with="platformUrl,artifactoryUrl,instance.timeout,instance.bypassProxy,useCredentialsPlugin,credentialsId,username,password,connectionRetry"/> + checked="${instance.resolverCredentialsConfig.overridingCredentials}"> - + - + - + + value="${instance.resolverCredentialsConfig.username}"/> + value="${instance.resolverCredentialsConfig.password}"/> diff --git a/src/main/resources/org/jfrog/hudson/ArtifactoryRedeployPublisher/config.jelly b/src/main/resources/org/jfrog/hudson/ArtifactoryRedeployPublisher/config.jelly index 0c0b785c0..5c04423d4 100644 --- a/src/main/resources/org/jfrog/hudson/ArtifactoryRedeployPublisher/config.jelly +++ b/src/main/resources/org/jfrog/hudson/ArtifactoryRedeployPublisher/config.jelly @@ -1,21 +1,21 @@ - - + + - - + + - - -
- + @@ -62,7 +62,7 @@ diff --git a/src/main/resources/org/jfrog/hudson/generic/ArtifactoryGenericConfigurator/config.jelly b/src/main/resources/org/jfrog/hudson/generic/ArtifactoryGenericConfigurator/config.jelly index c95fc28d6..7a5e22cc9 100644 --- a/src/main/resources/org/jfrog/hudson/generic/ArtifactoryGenericConfigurator/config.jelly +++ b/src/main/resources/org/jfrog/hudson/generic/ArtifactoryGenericConfigurator/config.jelly @@ -16,14 +16,14 @@ - - + + - + + id="artifactoryUrlDeploy${s.artifactoryServer.artifactoryUrl}" + value="${s.artifactoryServer.artifactoryUrl}"/> @@ -77,18 +77,18 @@ - - + + - + + id="artifactoryUrlDeploy${s.artifactoryServer.artifactoryUrl}" + value="${s.artifactoryServer.artifactoryUrl}"/> - @@ -141,14 +141,14 @@ - - + + - + + id="artifactoryUrlResolve${s.artifactoryServer.artifactoryUrl}" + value="${s.artifactoryServer.artifactoryUrl}"/> @@ -204,14 +204,14 @@ - - + + - + + id="artifactoryUrlResolve${s.artifactoryServer.artifactoryUrl}" + value="${s.artifactoryServer.artifactoryUrl}"/> diff --git a/src/main/resources/org/jfrog/hudson/gradle/ArtifactoryGradleConfigurator/config.jelly b/src/main/resources/org/jfrog/hudson/gradle/ArtifactoryGradleConfigurator/config.jelly index e075add76..136bf8419 100644 --- a/src/main/resources/org/jfrog/hudson/gradle/ArtifactoryGradleConfigurator/config.jelly +++ b/src/main/resources/org/jfrog/hudson/gradle/ArtifactoryGradleConfigurator/config.jelly @@ -5,16 +5,16 @@ - - + + - - + + -
- + @@ -73,15 +73,15 @@ - - + + - - + + - diff --git a/src/main/resources/org/jfrog/hudson/ivy/ArtifactoryIvyConfigurator/config.jelly b/src/main/resources/org/jfrog/hudson/ivy/ArtifactoryIvyConfigurator/config.jelly index fa2eed5fb..04212f0b3 100644 --- a/src/main/resources/org/jfrog/hudson/ivy/ArtifactoryIvyConfigurator/config.jelly +++ b/src/main/resources/org/jfrog/hudson/ivy/ArtifactoryIvyConfigurator/config.jelly @@ -5,14 +5,14 @@ - - + + - - + + - diff --git a/src/main/resources/org/jfrog/hudson/ivy/ArtifactoryIvyFreeStyleConfigurator/config.jelly b/src/main/resources/org/jfrog/hudson/ivy/ArtifactoryIvyFreeStyleConfigurator/config.jelly index 0ad8d759d..a5488f313 100644 --- a/src/main/resources/org/jfrog/hudson/ivy/ArtifactoryIvyFreeStyleConfigurator/config.jelly +++ b/src/main/resources/org/jfrog/hudson/ivy/ArtifactoryIvyFreeStyleConfigurator/config.jelly @@ -5,13 +5,13 @@ - - + + - - + + - diff --git a/src/main/resources/org/jfrog/hudson/maven3/ArtifactoryMaven3Configurator/config.jelly b/src/main/resources/org/jfrog/hudson/maven3/ArtifactoryMaven3Configurator/config.jelly index 1a9e50f09..cf4325bfd 100644 --- a/src/main/resources/org/jfrog/hudson/maven3/ArtifactoryMaven3Configurator/config.jelly +++ b/src/main/resources/org/jfrog/hudson/maven3/ArtifactoryMaven3Configurator/config.jelly @@ -21,20 +21,20 @@ - - + + - - + + - - @@ -68,29 +68,29 @@ checked="${instance.enableResolveArtifacts}"> - - + + - - + + - - diff --git a/src/main/resources/org/jfrog/hudson/maven3/ArtifactoryMaven3NativeConfigurator/config.jelly b/src/main/resources/org/jfrog/hudson/maven3/ArtifactoryMaven3NativeConfigurator/config.jelly index cf74ce2fe..62bef79ae 100644 --- a/src/main/resources/org/jfrog/hudson/maven3/ArtifactoryMaven3NativeConfigurator/config.jelly +++ b/src/main/resources/org/jfrog/hudson/maven3/ArtifactoryMaven3NativeConfigurator/config.jelly @@ -1,19 +1,19 @@ - - + + - - + + - - diff --git a/src/main/resources/org/jfrog/hudson/trigger/ArtifactoryTrigger/config.jelly b/src/main/resources/org/jfrog/hudson/trigger/ArtifactoryTrigger/config.jelly index 604279ca1..f78f11b6b 100644 --- a/src/main/resources/org/jfrog/hudson/trigger/ArtifactoryTrigger/config.jelly +++ b/src/main/resources/org/jfrog/hudson/trigger/ArtifactoryTrigger/config.jelly @@ -1,7 +1,7 @@ - - + diff --git a/src/main/webapp/help/ArtifactoryBuilder/help-url.html b/src/main/webapp/help/ArtifactoryBuilder/help-artifactory-url.html similarity index 100% rename from src/main/webapp/help/ArtifactoryBuilder/help-url.html rename to src/main/webapp/help/ArtifactoryBuilder/help-artifactory-url.html diff --git a/src/main/webapp/help/ArtifactoryBuilder/help-platform-url.html b/src/main/webapp/help/ArtifactoryBuilder/help-platform-url.html new file mode 100644 index 000000000..e719d0440 --- /dev/null +++ b/src/main/webapp/help/ArtifactoryBuilder/help-platform-url.html @@ -0,0 +1,4 @@ +
+ Specify the JFrog platform URL, like http://repo.jfrog.org/. + By default, Artifactory URL will be set to *PlatformUrl*/artifactory if not configured, e.g. http://repo.jfrog.org/artifactory +
\ No newline at end of file diff --git a/src/main/webapp/help/ArtifactoryBuilder/help-serverId.html b/src/main/webapp/help/ArtifactoryBuilder/help-serverId.html index ed9c3ce5a..9cb138472 100644 --- a/src/main/webapp/help/ArtifactoryBuilder/help-serverId.html +++ b/src/main/webapp/help/ArtifactoryBuilder/help-serverId.html @@ -1,3 +1,3 @@
- Server unique identifier. + Instance unique identifier.
\ No newline at end of file diff --git a/src/test/java/org/jfrog/hudson/pipeline/integration/CommonITestsPipeline.java b/src/test/java/org/jfrog/hudson/pipeline/integration/CommonITestsPipeline.java index ed4965301..66653db57 100644 --- a/src/test/java/org/jfrog/hudson/pipeline/integration/CommonITestsPipeline.java +++ b/src/test/java/org/jfrog/hudson/pipeline/integration/CommonITestsPipeline.java @@ -191,11 +191,11 @@ void downloadByShaAndBuildNameTest(String buildName) throws Exception { } } - void uploadTest(String buildName) throws Exception { + void uploadTest(String buildName, String pipelineName) throws Exception { Set expectedArtifacts = getTestFilesNamesByLayer(0); String buildNumber = "3"; - runPipeline("upload", false); + runPipeline(pipelineName, false); try { expectedArtifacts.forEach(artifactName -> assertTrue(artifactName + " doesn't exist in Artifactory", isExistInArtifactory(artifactoryClient, getRepoKey(TestRepository.LOCAL_REPO1), artifactName))); @@ -717,7 +717,7 @@ public void buildTriggerGlobalServerTest() throws Exception { ArtifactoryTrigger artifactoryTrigger = checkArtifactoryTrigger(run); // Change something in Artifactory server - ArtifactoryServer server = RepositoriesUtils.getArtifactoryServer("LOCAL", RepositoriesUtils.getArtifactoryServers()); + ArtifactoryServer server = RepositoriesUtils.getArtifactoryServer("LOCAL"); server.setConnectionRetry(4); // Make sure the change took place diff --git a/src/test/java/org/jfrog/hudson/pipeline/integration/DeclarativeITest.java b/src/test/java/org/jfrog/hudson/pipeline/integration/DeclarativeITest.java index 33e18e6be..b502bb42f 100644 --- a/src/test/java/org/jfrog/hudson/pipeline/integration/DeclarativeITest.java +++ b/src/test/java/org/jfrog/hudson/pipeline/integration/DeclarativeITest.java @@ -48,7 +48,12 @@ public void downloadByShaAndBuildNameTest() throws Exception { @Test public void uploadTest() throws Exception { - super.uploadTest("declarative:upload test"); + super.uploadTest("declarative:upload test","upload"); + } + + @Test + public void platformUploadTest() throws Exception { + super.uploadTest("declarative:upload test","uploadUsingPlatformConfig"); } @Test diff --git a/src/test/java/org/jfrog/hudson/pipeline/integration/ITestUtils.java b/src/test/java/org/jfrog/hudson/pipeline/integration/ITestUtils.java index 63b12d24e..3439114de 100644 --- a/src/test/java/org/jfrog/hudson/pipeline/integration/ITestUtils.java +++ b/src/test/java/org/jfrog/hudson/pipeline/integration/ITestUtils.java @@ -333,7 +333,7 @@ static ArtifactoryTrigger checkArtifactoryTrigger(WorkflowRun run) { assertNotNull(artifactoryTrigger); ArtifactoryServer server = artifactoryTrigger.getArtifactoryServer(); assertNotNull(server); - assertTrue(artifactoryTrigger.getArtifactoryServers().contains(server)); + assertTrue(artifactoryTrigger.getJfrogInstances().stream().anyMatch(s -> s.getArtifactoryServer().getServerId().equals(server.getServerId()))); assertEquals("libs-release-local", artifactoryTrigger.getPaths()); assertEquals("* * * * *", artifactoryTrigger.getSpec()); return artifactoryTrigger; diff --git a/src/test/java/org/jfrog/hudson/pipeline/integration/PipelineTestBase.java b/src/test/java/org/jfrog/hudson/pipeline/integration/PipelineTestBase.java index f87e0e166..57f0390f4 100644 --- a/src/test/java/org/jfrog/hudson/pipeline/integration/PipelineTestBase.java +++ b/src/test/java/org/jfrog/hudson/pipeline/integration/PipelineTestBase.java @@ -23,6 +23,7 @@ import org.jfrog.hudson.ArtifactoryBuilder; import org.jfrog.hudson.ArtifactoryServer; import org.jfrog.hudson.CredentialsConfig; +import org.jfrog.hudson.JFrogPlatformInstance; import org.jfrog.hudson.jfpipelines.JFrogPipelinesServer; import org.jfrog.hudson.jfpipelines.Utils; import org.junit.*; @@ -57,7 +58,8 @@ public class PipelineTestBase { public static TemporaryFolder testTemporaryFolder = new TemporaryFolder(); private static final String SLAVE_LABEL = "TestSlave"; - private static final String ARTIFACTORY_URL = System.getenv("JENKINS_ARTIFACTORY_URL"); + private static final String PLATFORM_URL = System.getenv("JENKINS_PLATFORM_URL"); + private static final String ARTIFACTORY_URL = org.apache.commons.lang.StringUtils.removeEnd(PLATFORM_URL, "/") + "/artifactory"; private static final String ARTIFACTORY_USERNAME = System.getenv("JENKINS_ARTIFACTORY_USERNAME"); private static final String ARTIFACTORY_PASSWORD = System.getenv("JENKINS_ARTIFACTORY_PASSWORD"); static final String JENKINS_XRAY_TEST_ENABLE = System.getenv("JENKINS_XRAY_TEST_ENABLE"); @@ -180,10 +182,12 @@ private static void setGlobalConfiguration() { JFrogPipelinesServer server = new JFrogPipelinesServer("http://127.0.0.1:1080", CredentialsConfig.EMPTY_CREDENTIALS_CONFIG, 300, false, 3); artifactoryBuilder.setJfrogPipelinesServer(server); CredentialsConfig cred = new CredentialsConfig("admin", "password", "cred1"); - List artifactoryServers = new ArrayList() {{ - add(new ArtifactoryServer("LOCAL", "http://127.0.0.1:8081/artifactory", cred, cred, 0, false, 3, null)); + CredentialsConfig platformCred = new CredentialsConfig(ARTIFACTORY_USERNAME, ARTIFACTORY_PASSWORD, null); + List artifactoryServers = new ArrayList() {{ + add(new JFrogPlatformInstance(new ArtifactoryServer("LOCAL", "http://127.0.0.1:8081/artifactory", cred, cred, 0, false, 3, null))); + add(new JFrogPlatformInstance("PLATFORM",PLATFORM_URL, ARTIFACTORY_URL, platformCred, platformCred, 0, false, 3, null)); }}; - artifactoryBuilder.setArtifactoryServers(artifactoryServers); + artifactoryBuilder.setJfrogInstances(artifactoryServers); } /** @@ -273,8 +277,8 @@ private String readPipeline(String name) throws IOException { * Verify ARTIFACTORY_URL, ARTIFACTORY_USERNAME and ARTIFACTORY_PASSWORD */ private static void verifyEnvironment() { - if (StringUtils.isBlank(ARTIFACTORY_URL)) { - throw new IllegalArgumentException("JENKINS_ARTIFACTORY_URL is not set"); + if (StringUtils.isBlank(PLATFORM_URL)) { + throw new IllegalArgumentException("JENKINS_PLATFORM_URL is not set"); } if (StringUtils.isBlank(ARTIFACTORY_USERNAME)) { throw new IllegalArgumentException("JENKINS_ARTIFACTORY_USERNAME is not set"); diff --git a/src/test/java/org/jfrog/hudson/pipeline/integration/ScriptedITest.java b/src/test/java/org/jfrog/hudson/pipeline/integration/ScriptedITest.java index 883bec2ec..745c82c46 100644 --- a/src/test/java/org/jfrog/hudson/pipeline/integration/ScriptedITest.java +++ b/src/test/java/org/jfrog/hudson/pipeline/integration/ScriptedITest.java @@ -48,7 +48,12 @@ public void downloadByShaAndBuildNameTest() throws Exception { @Test public void uploadTest() throws Exception { - super.uploadTest("scripted:upload test"); + super.uploadTest("scripted:upload test", "upload"); + } + + @Test + public void platformUploadTest() throws Exception { + super.uploadTest("scripted:platformUpload test", "uploadUsingPlatformConfig"); } @Test diff --git a/src/test/java/org/jfrog/hudson/util/converters/ArtifactoryBuilderConverterTest.java b/src/test/java/org/jfrog/hudson/util/converters/ArtifactoryBuilderConverterTest.java new file mode 100644 index 000000000..d4b1eaa64 --- /dev/null +++ b/src/test/java/org/jfrog/hudson/util/converters/ArtifactoryBuilderConverterTest.java @@ -0,0 +1,59 @@ +package org.jfrog.hudson.util.converters; + +import hudson.ExtensionList; +import jenkins.model.Jenkins; +import org.hamcrest.Matchers; +import org.jfrog.hudson.ArtifactoryBuilder; +import org.jfrog.hudson.JFrogPlatformInstance; +import org.junit.Assert; +import org.junit.ClassRule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsRule; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Objects; + +public class ArtifactoryBuilderConverterTest { + + private static final String SERVER_ID = "1"; + private static final String PLATFORM_URL = "https://jfrog.io"; + private static final String ARTIFACTORY_URL = "https://jfrog.io/artifactory"; + + @ClassRule + public static JenkinsRule jenkins = new JenkinsRule(); + + @Test + public void testConvertToArtifactoryServers_pre_3_10_6() throws IOException { + ArtifactoryBuilder.DescriptorImpl testBuilder = ExtensionList.lookupSingleton(ArtifactoryBuilder.DescriptorImpl.class); + File testFile = new File(getClass().getResource("/converters/config-3.10.6-1.xml").getFile()); + Path targetPath = new File(Jenkins.get().getRootDir(), ArtifactoryBuilder.class.getName() + ".xml").toPath(); + Files.copy(testFile.toPath(), targetPath); + testBuilder.load(); + Assert.assertThat(testBuilder.getJfrogInstances(), Matchers.hasSize(2)); + JFrogPlatformInstance jfrogServer = testBuilder.getJfrogInstances().get(0); + Assert.assertEquals(SERVER_ID, Objects.requireNonNull(jfrogServer.getId())); + Assert.assertEquals(SERVER_ID, Objects.requireNonNull(jfrogServer.getArtifactoryServer().getServerId())); + Assert.assertEquals(ARTIFACTORY_URL, Objects.requireNonNull(jfrogServer.getArtifactoryServer().getArtifactoryUrl())); + Assert.assertNull(jfrogServer.getUrl()); + Files.delete(targetPath); + } + + @Test + public void testConvertToArtifactoryServers_after_3_10_6() throws IOException { + ArtifactoryBuilder.DescriptorImpl testBuilder = ExtensionList.lookupSingleton(ArtifactoryBuilder.DescriptorImpl.class); + File testFile = new File(getClass().getResource("/converters/config-3.10.6-3.xml").getFile()); + Path targetPath = new File(Jenkins.get().getRootDir(), ArtifactoryBuilder.class.getName() + ".xml").toPath(); + Files.copy(testFile.toPath(), targetPath); + testBuilder.load(); + Assert.assertThat(testBuilder.getJfrogInstances(), Matchers.hasSize(1)); + JFrogPlatformInstance jfrogServer = testBuilder.getJfrogInstances().get(0); + Assert.assertEquals(SERVER_ID, Objects.requireNonNull(jfrogServer.getId())); + Assert.assertEquals(SERVER_ID, Objects.requireNonNull(jfrogServer.getArtifactoryServer().getServerId())); + Assert.assertEquals(ARTIFACTORY_URL, Objects.requireNonNull(jfrogServer.getArtifactoryServer().getArtifactoryUrl())); + Assert.assertEquals(PLATFORM_URL, Objects.requireNonNull(jfrogServer.getUrl())); + Files.delete(targetPath); + } +} diff --git a/src/test/java/org/jfrog/hudson/util/converters/CredentialsConfigConverterTest.java b/src/test/java/org/jfrog/hudson/util/converters/CredentialsConfigConverterTest.java index 77137d872..16e405f4a 100644 --- a/src/test/java/org/jfrog/hudson/util/converters/CredentialsConfigConverterTest.java +++ b/src/test/java/org/jfrog/hudson/util/converters/CredentialsConfigConverterTest.java @@ -24,16 +24,16 @@ public class CredentialsConfigConverterTest { @ClassRule public static JenkinsRule jenkins = new JenkinsRule(); - + @Test public void testConvertToSecret_pre_3_6_0() throws IOException { ArtifactoryBuilder.DescriptorImpl testBuilder = ExtensionList.lookupSingleton(ArtifactoryBuilder.DescriptorImpl.class); - + File testFile = new File(getClass().getResource("/converters/config-3.5.0.xml").getFile()); Files.copy(testFile.toPath(), new File(Jenkins.get().getRootDir(), ArtifactoryBuilder.class.getName() + ".xml").toPath()); testBuilder.load(); - Assert.assertThat(testBuilder.getArtifactoryServers(), Matchers.hasSize(1)); - ArtifactoryServer artifactoryServer = testBuilder.getArtifactoryServers().get(0); + Assert.assertThat(testBuilder.getJfrogInstances(), Matchers.hasSize(1)); + ArtifactoryServer artifactoryServer = testBuilder.getJfrogInstances().get(0).getArtifactoryServer(); Assert.assertEquals(DEPLOYER_USERNAME, Objects.requireNonNull(artifactoryServer.getDeployerCredentialsConfig().getUsername())); Assert.assertEquals(DEPLOYER_PASSWORD, Objects.requireNonNull(artifactoryServer.getDeployerCredentialsConfig().getPassword()).getPlainText()); Assert.assertEquals(RESOLVER_USERNAME, Objects.requireNonNull(artifactoryServer.getResolverCredentialsConfig().getUsername())); diff --git a/src/test/resources/converters/config-3.10.6-1.xml b/src/test/resources/converters/config-3.10.6-1.xml new file mode 100644 index 000000000..8263148c1 --- /dev/null +++ b/src/test/resources/converters/config-3.10.6-1.xml @@ -0,0 +1,49 @@ + + + true + + + https://jfrog.io/artifactory + 1 + 300 + false + 3 + 3 + + {JGVjcmV0RGVwbG95ZXI=} + {JGVjcmV0RGVwbG95ZXI=} + eco1 + false + false + + + + https://io/artifactory + 2 + 300 + false + 3 + 3 + + {JGVjcmV0RGVwbG95ZXI=} + {JGVjcmV0RGVwbG95ZXI=} + eco2 + false + false + + + + + + {JGVjcmV0RGVwbG95ZXI=} + {JGVjcmV0RGVwbG95ZXI=} + + false + true + + 3 + + false + 300 + + \ No newline at end of file diff --git a/src/test/resources/converters/config-3.10.6-3.xml b/src/test/resources/converters/config-3.10.6-3.xml new file mode 100644 index 000000000..359016fd4 --- /dev/null +++ b/src/test/resources/converters/config-3.10.6-3.xml @@ -0,0 +1,61 @@ + + + true + + + https://jfrog.io + 1 + + https://jfrog.io/artifactory + 1 + 300 + false + 3 + 3 + + {JGVjcmV0RGVwbG95ZXI=} + {JGVjcmV0RGVwbG95ZXI=} + eco3 + false + false + + + + + + + + https://jfrog.io/artifactory + oe + 300 + false + 3 + 3 + + {JGVjcmV0RGVwbG95ZXI=} + {JGVjcmV0RGVwbG95ZXI=} + eco3 + false + false + + + + false + false + + + + + + {JGVjcmV0RGVwbG95ZXI=} + {JGVjcmV0RGVwbG95ZXI=} + + false + true + + 3 + + false + 300 + + \ No newline at end of file diff --git a/src/test/resources/integration/pipelines/declarative/buildAppend.pipeline b/src/test/resources/integration/pipelines/declarative/buildAppend.pipeline index d8a330327..4c6157b15 100644 --- a/src/test/resources/integration/pipelines/declarative/buildAppend.pipeline +++ b/src/test/resources/integration/pipelines/declarative/buildAppend.pipeline @@ -10,7 +10,7 @@ node("TestSlave") { stage "Configuration" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/collectIssues.pipeline b/src/test/resources/integration/pipelines/declarative/collectIssues.pipeline index 0e370a7bc..4bb71de51 100644 --- a/src/test/resources/integration/pipelines/declarative/collectIssues.pipeline +++ b/src/test/resources/integration/pipelines/declarative/collectIssues.pipeline @@ -8,7 +8,7 @@ node("TestSlave") { stage "Configuration" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/conan.pipeline b/src/test/resources/integration/pipelines/declarative/conan.pipeline index 069d47468..55fb4ca6f 100644 --- a/src/test/resources/integration/pipelines/declarative/conan.pipeline +++ b/src/test/resources/integration/pipelines/declarative/conan.pipeline @@ -12,7 +12,7 @@ node("TestSlave") { stage "Configure Artifactory" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/deleteProps.pipeline b/src/test/resources/integration/pipelines/declarative/deleteProps.pipeline index 83f03f1a6..8eb6dde89 100644 --- a/src/test/resources/integration/pipelines/declarative/deleteProps.pipeline +++ b/src/test/resources/integration/pipelines/declarative/deleteProps.pipeline @@ -8,7 +8,7 @@ node("TestSlave") { stage "Configuration" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/dockerPull.pipeline b/src/test/resources/integration/pipelines/declarative/dockerPull.pipeline index a05c53582..8d593a348 100644 --- a/src/test/resources/integration/pipelines/declarative/dockerPull.pipeline +++ b/src/test/resources/integration/pipelines/declarative/dockerPull.pipeline @@ -14,7 +14,7 @@ node("TestSlave") { stage "rtserverconfig" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/dockerPush.pipeline b/src/test/resources/integration/pipelines/declarative/dockerPush.pipeline index 15890fea9..ca8ee8070 100644 --- a/src/test/resources/integration/pipelines/declarative/dockerPush.pipeline +++ b/src/test/resources/integration/pipelines/declarative/dockerPush.pipeline @@ -14,7 +14,7 @@ node("TestSlave") { stage "rtserverconfig" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/dotnet.pipeline b/src/test/resources/integration/pipelines/declarative/dotnet.pipeline index def4aaacd..f95faa4ba 100644 --- a/src/test/resources/integration/pipelines/declarative/dotnet.pipeline +++ b/src/test/resources/integration/pipelines/declarative/dotnet.pipeline @@ -12,7 +12,7 @@ node("TestSlave") { stage "Configure Artifactory" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/downloadByAql.pipeline b/src/test/resources/integration/pipelines/declarative/downloadByAql.pipeline index 99df27510..a365bae7b 100644 --- a/src/test/resources/integration/pipelines/declarative/downloadByAql.pipeline +++ b/src/test/resources/integration/pipelines/declarative/downloadByAql.pipeline @@ -8,7 +8,7 @@ node("TestSlave") { stage "Configuration" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/downloadByBuildOnly.pipeline b/src/test/resources/integration/pipelines/declarative/downloadByBuildOnly.pipeline index c3b5261d1..b8abde893 100644 --- a/src/test/resources/integration/pipelines/declarative/downloadByBuildOnly.pipeline +++ b/src/test/resources/integration/pipelines/declarative/downloadByBuildOnly.pipeline @@ -6,7 +6,7 @@ node("TestSlave") { stage "Configuration" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/downloadByPattern.pipeline b/src/test/resources/integration/pipelines/declarative/downloadByPattern.pipeline index 3c5dbfcfa..3215637b0 100644 --- a/src/test/resources/integration/pipelines/declarative/downloadByPattern.pipeline +++ b/src/test/resources/integration/pipelines/declarative/downloadByPattern.pipeline @@ -8,7 +8,7 @@ node("TestSlave") { stage "Configuration" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/downloadByPatternAndBuild.pipeline b/src/test/resources/integration/pipelines/declarative/downloadByPatternAndBuild.pipeline index dc5015d20..102dc7dfc 100644 --- a/src/test/resources/integration/pipelines/declarative/downloadByPatternAndBuild.pipeline +++ b/src/test/resources/integration/pipelines/declarative/downloadByPatternAndBuild.pipeline @@ -6,7 +6,7 @@ node("TestSlave") { stage "Configuration" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/downloadByShaAndBuild.pipeline b/src/test/resources/integration/pipelines/declarative/downloadByShaAndBuild.pipeline index 0fe7a4419..99a5879bc 100644 --- a/src/test/resources/integration/pipelines/declarative/downloadByShaAndBuild.pipeline +++ b/src/test/resources/integration/pipelines/declarative/downloadByShaAndBuild.pipeline @@ -6,7 +6,7 @@ node("TestSlave") { stage "Configuration" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/downloadByShaAndBuildName.pipeline b/src/test/resources/integration/pipelines/declarative/downloadByShaAndBuildName.pipeline index 4e35e29e9..51f86c6a4 100644 --- a/src/test/resources/integration/pipelines/declarative/downloadByShaAndBuildName.pipeline +++ b/src/test/resources/integration/pipelines/declarative/downloadByShaAndBuildName.pipeline @@ -6,7 +6,7 @@ node("TestSlave") { stage "Configuration" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/downloadFailNoOp.pipeline b/src/test/resources/integration/pipelines/declarative/downloadFailNoOp.pipeline index d19577de8..c8f890341 100644 --- a/src/test/resources/integration/pipelines/declarative/downloadFailNoOp.pipeline +++ b/src/test/resources/integration/pipelines/declarative/downloadFailNoOp.pipeline @@ -6,7 +6,7 @@ node("TestSlave") { stage "Configuration" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/downloadNonExistingBuild.pipeline b/src/test/resources/integration/pipelines/declarative/downloadNonExistingBuild.pipeline index d4c9c2852..f473ebd1b 100644 --- a/src/test/resources/integration/pipelines/declarative/downloadNonExistingBuild.pipeline +++ b/src/test/resources/integration/pipelines/declarative/downloadNonExistingBuild.pipeline @@ -8,7 +8,7 @@ node("TestSlave") { stage "Configuration" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/go.pipeline b/src/test/resources/integration/pipelines/declarative/go.pipeline index dafea97b3..6b06ced4f 100644 --- a/src/test/resources/integration/pipelines/declarative/go.pipeline +++ b/src/test/resources/integration/pipelines/declarative/go.pipeline @@ -12,7 +12,7 @@ node("TestSlave") { stage "Configure Artifactory" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/goCustomModuleName.pipeline b/src/test/resources/integration/pipelines/declarative/goCustomModuleName.pipeline index 7067148f3..79af40e88 100644 --- a/src/test/resources/integration/pipelines/declarative/goCustomModuleName.pipeline +++ b/src/test/resources/integration/pipelines/declarative/goCustomModuleName.pipeline @@ -12,7 +12,7 @@ node("TestSlave") { stage "Configure Artifactory" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/gradle.pipeline b/src/test/resources/integration/pipelines/declarative/gradle.pipeline index cb4cf4248..b90da721d 100644 --- a/src/test/resources/integration/pipelines/declarative/gradle.pipeline +++ b/src/test/resources/integration/pipelines/declarative/gradle.pipeline @@ -14,7 +14,7 @@ node("TestSlave") { stage "Configure Artifactory" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/gradleCiServer.pipeline b/src/test/resources/integration/pipelines/declarative/gradleCiServer.pipeline index 88c238f89..126189397 100644 --- a/src/test/resources/integration/pipelines/declarative/gradleCiServer.pipeline +++ b/src/test/resources/integration/pipelines/declarative/gradleCiServer.pipeline @@ -12,7 +12,7 @@ node("TestSlave") { stage "Configure Artifactory" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/gradleCiServerPublication.pipeline b/src/test/resources/integration/pipelines/declarative/gradleCiServerPublication.pipeline index 48ab9602a..11a6f9577 100644 --- a/src/test/resources/integration/pipelines/declarative/gradleCiServerPublication.pipeline +++ b/src/test/resources/integration/pipelines/declarative/gradleCiServerPublication.pipeline @@ -12,7 +12,7 @@ node("TestSlave") { stage "Configure Artifactory" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/maven.pipeline b/src/test/resources/integration/pipelines/declarative/maven.pipeline index abc973678..295250b59 100644 --- a/src/test/resources/integration/pipelines/declarative/maven.pipeline +++ b/src/test/resources/integration/pipelines/declarative/maven.pipeline @@ -14,7 +14,7 @@ node("TestSlave") { stage "Configure Artifactory" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/npmCi.pipeline b/src/test/resources/integration/pipelines/declarative/npmCi.pipeline index 8cbe84941..c653978c1 100644 --- a/src/test/resources/integration/pipelines/declarative/npmCi.pipeline +++ b/src/test/resources/integration/pipelines/declarative/npmCi.pipeline @@ -12,7 +12,7 @@ node("TestSlave") { stage "Configure Artifactory" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/npmCustomModuleName.pipeline b/src/test/resources/integration/pipelines/declarative/npmCustomModuleName.pipeline index 695e92fea..bbaea13d3 100644 --- a/src/test/resources/integration/pipelines/declarative/npmCustomModuleName.pipeline +++ b/src/test/resources/integration/pipelines/declarative/npmCustomModuleName.pipeline @@ -12,7 +12,7 @@ node("TestSlave") { stage "Configure Artifactory" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/npmInstall.pipeline b/src/test/resources/integration/pipelines/declarative/npmInstall.pipeline index 511cea0aa..f50ec35b1 100644 --- a/src/test/resources/integration/pipelines/declarative/npmInstall.pipeline +++ b/src/test/resources/integration/pipelines/declarative/npmInstall.pipeline @@ -12,7 +12,7 @@ node("TestSlave") { stage "Configure Artifactory" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/nuget.pipeline b/src/test/resources/integration/pipelines/declarative/nuget.pipeline index bf373fcea..c95cb8b52 100644 --- a/src/test/resources/integration/pipelines/declarative/nuget.pipeline +++ b/src/test/resources/integration/pipelines/declarative/nuget.pipeline @@ -12,7 +12,7 @@ node("TestSlave") { stage "Configure Artifactory" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/pip.pipeline b/src/test/resources/integration/pipelines/declarative/pip.pipeline index 1fa87cc65..93e25f4e9 100644 --- a/src/test/resources/integration/pipelines/declarative/pip.pipeline +++ b/src/test/resources/integration/pipelines/declarative/pip.pipeline @@ -12,7 +12,7 @@ node("TestSlave") { stage "Configure Artifactory" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/promote.pipeline b/src/test/resources/integration/pipelines/declarative/promote.pipeline index 12ed124ce..fba39b1b9 100644 --- a/src/test/resources/integration/pipelines/declarative/promote.pipeline +++ b/src/test/resources/integration/pipelines/declarative/promote.pipeline @@ -8,7 +8,7 @@ node("TestSlave") { stage "Configuration" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/setProps.pipeline b/src/test/resources/integration/pipelines/declarative/setProps.pipeline index f80bf2f6b..2156e29bb 100644 --- a/src/test/resources/integration/pipelines/declarative/setProps.pipeline +++ b/src/test/resources/integration/pipelines/declarative/setProps.pipeline @@ -8,7 +8,7 @@ node("TestSlave") { stage "Configuration" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/upload.pipeline b/src/test/resources/integration/pipelines/declarative/upload.pipeline index 87e4f9770..93cffb606 100644 --- a/src/test/resources/integration/pipelines/declarative/upload.pipeline +++ b/src/test/resources/integration/pipelines/declarative/upload.pipeline @@ -8,7 +8,7 @@ node("TestSlave") { stage "Configuration" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/uploadDownloadCustomModuleName.pipeline b/src/test/resources/integration/pipelines/declarative/uploadDownloadCustomModuleName.pipeline index ef180e7cb..81ef06363 100644 --- a/src/test/resources/integration/pipelines/declarative/uploadDownloadCustomModuleName.pipeline +++ b/src/test/resources/integration/pipelines/declarative/uploadDownloadCustomModuleName.pipeline @@ -8,7 +8,7 @@ node("TestSlave") { stage "Configuration" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/uploadFailNoOp.pipeline b/src/test/resources/integration/pipelines/declarative/uploadFailNoOp.pipeline index 727093fc0..bdb30efea 100644 --- a/src/test/resources/integration/pipelines/declarative/uploadFailNoOp.pipeline +++ b/src/test/resources/integration/pipelines/declarative/uploadFailNoOp.pipeline @@ -6,7 +6,7 @@ node("TestSlave") { stage "Configuration" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/uploadUsingPlatformConfig.pipeline b/src/test/resources/integration/pipelines/declarative/uploadUsingPlatformConfig.pipeline new file mode 100644 index 000000000..bef5b9cd1 --- /dev/null +++ b/src/test/resources/integration/pipelines/declarative/uploadUsingPlatformConfig.pipeline @@ -0,0 +1,32 @@ +package integration.pipelines.declarative + +node("TestSlave") { + def serverId = "PLATFORM" + def buildName = "declarative:upload test" + def buildNumber = "3" + + stage "Configuration" + + stage "Upload" + rtUpload( + serverId: serverId, + buildName: buildName, + buildNumber: buildNumber, + spec: """{ + "files": [ + { + "pattern": "${FILES_DIR}", + "target": "${LOCAL_REPO1}/", + "recursive": "false" + } + ] + }""" + ) + + stage "Publish Build Info" + rtPublishBuildInfo( + serverId: serverId, + buildName: buildName, + buildNumber: buildNumber + ) +} diff --git a/src/test/resources/integration/pipelines/declarative/uploadWithProps.pipeline b/src/test/resources/integration/pipelines/declarative/uploadWithProps.pipeline index 88435787e..552db672e 100644 --- a/src/test/resources/integration/pipelines/declarative/uploadWithProps.pipeline +++ b/src/test/resources/integration/pipelines/declarative/uploadWithProps.pipeline @@ -8,7 +8,7 @@ node("TestSlave") { stage "Configuration" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/xrayScanFailBuildFalse.pipeline b/src/test/resources/integration/pipelines/declarative/xrayScanFailBuildFalse.pipeline index 600b596bf..2675c5d2d 100644 --- a/src/test/resources/integration/pipelines/declarative/xrayScanFailBuildFalse.pipeline +++ b/src/test/resources/integration/pipelines/declarative/xrayScanFailBuildFalse.pipeline @@ -12,7 +12,7 @@ node("TestSlave") { stage "Configure Artifactory" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/declarative/xrayScanFailBuildTrue.pipeline b/src/test/resources/integration/pipelines/declarative/xrayScanFailBuildTrue.pipeline index 68deadeee..00d11a1ec 100644 --- a/src/test/resources/integration/pipelines/declarative/xrayScanFailBuildTrue.pipeline +++ b/src/test/resources/integration/pipelines/declarative/xrayScanFailBuildTrue.pipeline @@ -12,7 +12,7 @@ node("TestSlave") { stage "Configure Artifactory" rtServer( id: serverId, - url: "${env.JENKINS_ARTIFACTORY_URL}", + url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" ) diff --git a/src/test/resources/integration/pipelines/scripted/append.pipeline b/src/test/resources/integration/pipelines/scripted/append.pipeline index 57e846429..825e98422 100644 --- a/src/test/resources/integration/pipelines/scripted/append.pipeline +++ b/src/test/resources/integration/pipelines/scripted/append.pipeline @@ -13,7 +13,7 @@ node { buildInfoUpload.number = "13" stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" // Collect issues stage "Collect Issues" diff --git a/src/test/resources/integration/pipelines/scripted/buildAppend.pipeline b/src/test/resources/integration/pipelines/scripted/buildAppend.pipeline index 788265364..22d23484a 100644 --- a/src/test/resources/integration/pipelines/scripted/buildAppend.pipeline +++ b/src/test/resources/integration/pipelines/scripted/buildAppend.pipeline @@ -2,7 +2,7 @@ package integration.pipelines.scripted node("TestSlave") { stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" stage "Create 1st Build Info" def buildInfo1 = Artifactory.newBuildInfo() diff --git a/src/test/resources/integration/pipelines/scripted/collectIssues.pipeline b/src/test/resources/integration/pipelines/scripted/collectIssues.pipeline index 3cdc0c46a..cb7280e2d 100644 --- a/src/test/resources/integration/pipelines/scripted/collectIssues.pipeline +++ b/src/test/resources/integration/pipelines/scripted/collectIssues.pipeline @@ -4,7 +4,7 @@ node("TestSlave") { // Move to the scope of the test's git dir("${TEST_TEMP_FOLDER}") { stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" // Create build info def buildInfo = Artifactory.newBuildInfo() diff --git a/src/test/resources/integration/pipelines/scripted/conan.pipeline b/src/test/resources/integration/pipelines/scripted/conan.pipeline index 5a763bd7d..7f1a76ba3 100644 --- a/src/test/resources/integration/pipelines/scripted/conan.pipeline +++ b/src/test/resources/integration/pipelines/scripted/conan.pipeline @@ -2,7 +2,7 @@ package integration.pipelines.scripted node("TestSlave") { stage "Configure Artifactory" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:conan test" buildInfo.number = "7" diff --git a/src/test/resources/integration/pipelines/scripted/deleteProps.pipeline b/src/test/resources/integration/pipelines/scripted/deleteProps.pipeline index 5ef8b3f38..b181a6f59 100644 --- a/src/test/resources/integration/pipelines/scripted/deleteProps.pipeline +++ b/src/test/resources/integration/pipelines/scripted/deleteProps.pipeline @@ -2,7 +2,7 @@ package integration.pipelines.scripted node("TestSlave") { stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:deleteProps test" buildInfo.number = "3" diff --git a/src/test/resources/integration/pipelines/scripted/dockerPull.pipeline b/src/test/resources/integration/pipelines/scripted/dockerPull.pipeline index f4dc7b893..4f35310eb 100644 --- a/src/test/resources/integration/pipelines/scripted/dockerPull.pipeline +++ b/src/test/resources/integration/pipelines/scripted/dockerPull.pipeline @@ -7,7 +7,7 @@ node("TestSlave") { } def imageName = domainName + "hello-world:latest" def sourceRepo = "${env.JENKINS_ARTIFACTORY_DOCKER_PULL_REPO}" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" stage "dockerPull" def rtDocker = Artifactory.docker (rtServer, "${env.JENKINS_ARTIFACTORY_DOCKER_HOST}") diff --git a/src/test/resources/integration/pipelines/scripted/dockerPush.pipeline b/src/test/resources/integration/pipelines/scripted/dockerPush.pipeline index d1ec3c03e..c4cd71307 100644 --- a/src/test/resources/integration/pipelines/scripted/dockerPush.pipeline +++ b/src/test/resources/integration/pipelines/scripted/dockerPush.pipeline @@ -7,7 +7,7 @@ node("TestSlave") { } def imageName = domainName + "jfrog_artifactory_jenkins_tests:2" def targetRepo = "${env.JENKINS_ARTIFACTORY_DOCKER_PUSH_REPO}" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" stage "dockerPush" def rtDocker = Artifactory.docker (rtServer, "${env.JENKINS_ARTIFACTORY_DOCKER_HOST}") diff --git a/src/test/resources/integration/pipelines/scripted/dotnet.pipeline b/src/test/resources/integration/pipelines/scripted/dotnet.pipeline index 8b5b3992c..a308e9eb0 100644 --- a/src/test/resources/integration/pipelines/scripted/dotnet.pipeline +++ b/src/test/resources/integration/pipelines/scripted/dotnet.pipeline @@ -6,7 +6,7 @@ import java.nio.file.Paths node("TestSlave") { stage "Configure Artifactory" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:dotnet test" buildInfo.number = "13" diff --git a/src/test/resources/integration/pipelines/scripted/downloadByAql.pipeline b/src/test/resources/integration/pipelines/scripted/downloadByAql.pipeline index f1b3be500..cf011f749 100644 --- a/src/test/resources/integration/pipelines/scripted/downloadByAql.pipeline +++ b/src/test/resources/integration/pipelines/scripted/downloadByAql.pipeline @@ -2,7 +2,7 @@ package integration.pipelines.scripted node("TestSlave") { stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:downloadByAql test" buildInfo.number = "3" diff --git a/src/test/resources/integration/pipelines/scripted/downloadByBuildOnly.pipeline b/src/test/resources/integration/pipelines/scripted/downloadByBuildOnly.pipeline index 75d723ef2..3c5481731 100644 --- a/src/test/resources/integration/pipelines/scripted/downloadByBuildOnly.pipeline +++ b/src/test/resources/integration/pipelines/scripted/downloadByBuildOnly.pipeline @@ -2,7 +2,7 @@ package integration.pipelines.scripted node("TestSlave") { stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" // First upload files with buildNumber = 3 def buildInfo = Artifactory.newBuildInfo() diff --git a/src/test/resources/integration/pipelines/scripted/downloadByPattern.pipeline b/src/test/resources/integration/pipelines/scripted/downloadByPattern.pipeline index da036be15..86593fee2 100644 --- a/src/test/resources/integration/pipelines/scripted/downloadByPattern.pipeline +++ b/src/test/resources/integration/pipelines/scripted/downloadByPattern.pipeline @@ -2,7 +2,7 @@ package integration.pipelines.scripted node("TestSlave") { stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:downloadByPattern test" buildInfo.number = "3" diff --git a/src/test/resources/integration/pipelines/scripted/downloadByPatternAndBuild.pipeline b/src/test/resources/integration/pipelines/scripted/downloadByPatternAndBuild.pipeline index 31dc9d974..a97ebbe1e 100644 --- a/src/test/resources/integration/pipelines/scripted/downloadByPatternAndBuild.pipeline +++ b/src/test/resources/integration/pipelines/scripted/downloadByPatternAndBuild.pipeline @@ -2,7 +2,7 @@ package integration.pipelines.scripted node("TestSlave") { stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" // First upload files with buildNumber = 3 def buildInfo = Artifactory.newBuildInfo() diff --git a/src/test/resources/integration/pipelines/scripted/downloadByShaAndBuild.pipeline b/src/test/resources/integration/pipelines/scripted/downloadByShaAndBuild.pipeline index 69a289548..d11223916 100644 --- a/src/test/resources/integration/pipelines/scripted/downloadByShaAndBuild.pipeline +++ b/src/test/resources/integration/pipelines/scripted/downloadByShaAndBuild.pipeline @@ -2,7 +2,7 @@ package integration.pipelines.scripted node("TestSlave") { stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" // First upload files with buildNumber = 3 def buildInfo = Artifactory.newBuildInfo() diff --git a/src/test/resources/integration/pipelines/scripted/downloadByShaAndBuildName.pipeline b/src/test/resources/integration/pipelines/scripted/downloadByShaAndBuildName.pipeline index 2d0c0e644..4f81db28f 100644 --- a/src/test/resources/integration/pipelines/scripted/downloadByShaAndBuildName.pipeline +++ b/src/test/resources/integration/pipelines/scripted/downloadByShaAndBuildName.pipeline @@ -2,7 +2,7 @@ package integration.pipelines.scripted node("TestSlave") { stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" // First upload files with buildNumber = 3 def buildInfo = Artifactory.newBuildInfo() diff --git a/src/test/resources/integration/pipelines/scripted/downloadFailNoOp.pipeline b/src/test/resources/integration/pipelines/scripted/downloadFailNoOp.pipeline index 1fd312a84..69bd930ba 100644 --- a/src/test/resources/integration/pipelines/scripted/downloadFailNoOp.pipeline +++ b/src/test/resources/integration/pipelines/scripted/downloadFailNoOp.pipeline @@ -2,7 +2,7 @@ package integration.pipelines.scripted node("TestSlave") { stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" stage "Download" def downloadSpec = """{ diff --git a/src/test/resources/integration/pipelines/scripted/downloadNonExistingBuild.pipeline b/src/test/resources/integration/pipelines/scripted/downloadNonExistingBuild.pipeline index 151e9507b..f26e097d6 100644 --- a/src/test/resources/integration/pipelines/scripted/downloadNonExistingBuild.pipeline +++ b/src/test/resources/integration/pipelines/scripted/downloadNonExistingBuild.pipeline @@ -2,7 +2,7 @@ package integration.pipelines.scripted node("TestSlave") { stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" // First upload files and publish build def buildInfo = Artifactory.newBuildInfo() diff --git a/src/test/resources/integration/pipelines/scripted/go.pipeline b/src/test/resources/integration/pipelines/scripted/go.pipeline index ed00f5a00..e802a48e4 100644 --- a/src/test/resources/integration/pipelines/scripted/go.pipeline +++ b/src/test/resources/integration/pipelines/scripted/go.pipeline @@ -6,7 +6,7 @@ import java.nio.file.Paths node("TestSlave") { stage "Configure Artifactory" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:go test" buildInfo.number = "7" diff --git a/src/test/resources/integration/pipelines/scripted/goCustomModuleName.pipeline b/src/test/resources/integration/pipelines/scripted/goCustomModuleName.pipeline index e124d7092..1faa00e28 100644 --- a/src/test/resources/integration/pipelines/scripted/goCustomModuleName.pipeline +++ b/src/test/resources/integration/pipelines/scripted/goCustomModuleName.pipeline @@ -6,7 +6,7 @@ import java.nio.file.Paths node("TestSlave") { stage "Configure Artifactory" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:goCustomModuleName test" buildInfo.number = "7" diff --git a/src/test/resources/integration/pipelines/scripted/gradle.pipeline b/src/test/resources/integration/pipelines/scripted/gradle.pipeline index 317306c2a..8c7a1d877 100644 --- a/src/test/resources/integration/pipelines/scripted/gradle.pipeline +++ b/src/test/resources/integration/pipelines/scripted/gradle.pipeline @@ -8,7 +8,7 @@ env.DONT_COLLECT='FOO' env.COLLECT='BAR' node("TestSlave") { stage "Configure Artifactory" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.env.capture = true buildInfo.env.filter.addExclude("DONT_COLLECT") diff --git a/src/test/resources/integration/pipelines/scripted/gradleCiServer.pipeline b/src/test/resources/integration/pipelines/scripted/gradleCiServer.pipeline index c0ab7919f..17512ef84 100644 --- a/src/test/resources/integration/pipelines/scripted/gradleCiServer.pipeline +++ b/src/test/resources/integration/pipelines/scripted/gradleCiServer.pipeline @@ -6,7 +6,7 @@ import java.nio.file.Paths node("TestSlave") { stage "Configure Artifactory" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:gradle-ci test" buildInfo.number = "3" diff --git a/src/test/resources/integration/pipelines/scripted/gradleCiServerPublication.pipeline b/src/test/resources/integration/pipelines/scripted/gradleCiServerPublication.pipeline index 28163e034..7e6b35b99 100644 --- a/src/test/resources/integration/pipelines/scripted/gradleCiServerPublication.pipeline +++ b/src/test/resources/integration/pipelines/scripted/gradleCiServerPublication.pipeline @@ -6,7 +6,7 @@ import java.nio.file.Paths node("TestSlave") { stage "Configure Artifactory" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:gradle-ci-publication test" buildInfo.number = "3" diff --git a/src/test/resources/integration/pipelines/scripted/maven.pipeline b/src/test/resources/integration/pipelines/scripted/maven.pipeline index efc4590be..ad738cd3e 100644 --- a/src/test/resources/integration/pipelines/scripted/maven.pipeline +++ b/src/test/resources/integration/pipelines/scripted/maven.pipeline @@ -8,7 +8,7 @@ env.DONT_COLLECT='FOO' env.COLLECT='BAR' node("TestSlave") { stage "Configure Artifactory" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.env.capture = true buildInfo.env.filter.addExclude("DONT_COLLECT") diff --git a/src/test/resources/integration/pipelines/scripted/npmCi.pipeline b/src/test/resources/integration/pipelines/scripted/npmCi.pipeline index 7132ff110..729a7ac89 100644 --- a/src/test/resources/integration/pipelines/scripted/npmCi.pipeline +++ b/src/test/resources/integration/pipelines/scripted/npmCi.pipeline @@ -6,7 +6,7 @@ import java.nio.file.Paths node("TestSlave") { stage "Configure Artifactory" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:npm ci test" buildInfo.number = "4" diff --git a/src/test/resources/integration/pipelines/scripted/npmCustomModuleName.pipeline b/src/test/resources/integration/pipelines/scripted/npmCustomModuleName.pipeline index 55ab59d1a..a4e58e96d 100644 --- a/src/test/resources/integration/pipelines/scripted/npmCustomModuleName.pipeline +++ b/src/test/resources/integration/pipelines/scripted/npmCustomModuleName.pipeline @@ -6,7 +6,7 @@ import java.nio.file.Paths node("TestSlave") { stage "Configure Artifactory" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:npmCustomModuleName test" buildInfo.number = "3" diff --git a/src/test/resources/integration/pipelines/scripted/npmInstall.pipeline b/src/test/resources/integration/pipelines/scripted/npmInstall.pipeline index e1e55a0a9..d6bbcac96 100644 --- a/src/test/resources/integration/pipelines/scripted/npmInstall.pipeline +++ b/src/test/resources/integration/pipelines/scripted/npmInstall.pipeline @@ -6,7 +6,7 @@ import java.nio.file.Paths node("TestSlave") { stage "Configure Artifactory" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:npm install test" buildInfo.number = "3" diff --git a/src/test/resources/integration/pipelines/scripted/nuget.pipeline b/src/test/resources/integration/pipelines/scripted/nuget.pipeline index 859ca484e..c60bedb97 100644 --- a/src/test/resources/integration/pipelines/scripted/nuget.pipeline +++ b/src/test/resources/integration/pipelines/scripted/nuget.pipeline @@ -6,7 +6,7 @@ import java.nio.file.Paths node("TestSlave") { stage "Configure Artifactory" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:nuget test" buildInfo.number = "12" diff --git a/src/test/resources/integration/pipelines/scripted/pip.pipeline b/src/test/resources/integration/pipelines/scripted/pip.pipeline index 2d5dd31c9..53e3bc0ff 100644 --- a/src/test/resources/integration/pipelines/scripted/pip.pipeline +++ b/src/test/resources/integration/pipelines/scripted/pip.pipeline @@ -6,7 +6,7 @@ import java.nio.file.Paths node("TestSlave") { stage "Configure Artifactory" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:pip test" buildInfo.number = "4" diff --git a/src/test/resources/integration/pipelines/scripted/promote.pipeline b/src/test/resources/integration/pipelines/scripted/promote.pipeline index d4050eca1..1a1008375 100644 --- a/src/test/resources/integration/pipelines/scripted/promote.pipeline +++ b/src/test/resources/integration/pipelines/scripted/promote.pipeline @@ -2,7 +2,7 @@ package integration.pipelines.scripted node("TestSlave") { stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:promotion test" buildInfo.number = "4" diff --git a/src/test/resources/integration/pipelines/scripted/setProps.pipeline b/src/test/resources/integration/pipelines/scripted/setProps.pipeline index 132f5664d..be23ceda7 100644 --- a/src/test/resources/integration/pipelines/scripted/setProps.pipeline +++ b/src/test/resources/integration/pipelines/scripted/setProps.pipeline @@ -2,7 +2,7 @@ package integration.pipelines.scripted node("TestSlave") { stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:setProps test" buildInfo.number = "3" diff --git a/src/test/resources/integration/pipelines/scripted/upload.pipeline b/src/test/resources/integration/pipelines/scripted/upload.pipeline index c2e0a17b8..ea2a4da63 100644 --- a/src/test/resources/integration/pipelines/scripted/upload.pipeline +++ b/src/test/resources/integration/pipelines/scripted/upload.pipeline @@ -2,7 +2,7 @@ package integration.pipelines.scripted node("TestSlave") { stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:upload test" buildInfo.number = "3" diff --git a/src/test/resources/integration/pipelines/scripted/uploadDownloadCustomModuleName.pipeline b/src/test/resources/integration/pipelines/scripted/uploadDownloadCustomModuleName.pipeline index 8c41feb8d..6c7d6f4fc 100644 --- a/src/test/resources/integration/pipelines/scripted/uploadDownloadCustomModuleName.pipeline +++ b/src/test/resources/integration/pipelines/scripted/uploadDownloadCustomModuleName.pipeline @@ -2,7 +2,7 @@ package integration.pipelines.scripted node("TestSlave") { stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:uploadDownloadCustomModuleName test" buildInfo.number = "3" diff --git a/src/test/resources/integration/pipelines/scripted/uploadFailNoOp.pipeline b/src/test/resources/integration/pipelines/scripted/uploadFailNoOp.pipeline index 86d751ba1..a3c6f502b 100644 --- a/src/test/resources/integration/pipelines/scripted/uploadFailNoOp.pipeline +++ b/src/test/resources/integration/pipelines/scripted/uploadFailNoOp.pipeline @@ -2,7 +2,7 @@ package integration.pipelines.scripted node("TestSlave") { stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" stage "Upload" def uploadSpec = """{ diff --git a/src/test/resources/integration/pipelines/scripted/uploadUsingPlatformConfig.pipeline b/src/test/resources/integration/pipelines/scripted/uploadUsingPlatformConfig.pipeline new file mode 100644 index 000000000..d2739f59d --- /dev/null +++ b/src/test/resources/integration/pipelines/scripted/uploadUsingPlatformConfig.pipeline @@ -0,0 +1,24 @@ +package integration.pipelines.scripted + +node("TestSlave") { + stage "Configuration" + def artifactory = Jfrog.instance('PLATFORM').artifactory() + def buildInfo = Artifactory.newBuildInfo() + buildInfo.name = "scripted:platformUpload test" + buildInfo.number = "3" + + stage "Upload" + def uploadSpec = """{ + "files": [ + { + "pattern": "${FILES_DIR}", + "target": "${LOCAL_REPO1}/", + "recursive": "false" + } + ] + }""" + artifactory.upload spec: uploadSpec, buildInfo: buildInfo + + stage "Publish Build Info" + artifactory.publishBuildInfo buildInfo +} diff --git a/src/test/resources/integration/pipelines/scripted/uploadWithProps.pipeline b/src/test/resources/integration/pipelines/scripted/uploadWithProps.pipeline index 11ff3f388..5e314559e 100644 --- a/src/test/resources/integration/pipelines/scripted/uploadWithProps.pipeline +++ b/src/test/resources/integration/pipelines/scripted/uploadWithProps.pipeline @@ -2,7 +2,7 @@ package integration.pipelines.scripted node("TestSlave") { stage "Configuration" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:upload with props test" buildInfo.number = "3" diff --git a/src/test/resources/integration/pipelines/scripted/xrayScanFailBuildFalse.pipeline b/src/test/resources/integration/pipelines/scripted/xrayScanFailBuildFalse.pipeline index ef67e5668..b94f0d0a2 100644 --- a/src/test/resources/integration/pipelines/scripted/xrayScanFailBuildFalse.pipeline +++ b/src/test/resources/integration/pipelines/scripted/xrayScanFailBuildFalse.pipeline @@ -6,7 +6,7 @@ import java.nio.file.Paths node("TestSlave") { stage "Configure Artifactory" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:xrayScanFailBuildFalse test" buildInfo.number = "3" diff --git a/src/test/resources/integration/pipelines/scripted/xrayScanFailBuildTrue.pipeline b/src/test/resources/integration/pipelines/scripted/xrayScanFailBuildTrue.pipeline index e99fa1844..aa8a2a4c5 100644 --- a/src/test/resources/integration/pipelines/scripted/xrayScanFailBuildTrue.pipeline +++ b/src/test/resources/integration/pipelines/scripted/xrayScanFailBuildTrue.pipeline @@ -6,7 +6,7 @@ import java.nio.file.Paths node("TestSlave") { stage "Configure Artifactory" - def rtServer = Artifactory.newServer url: "${env.JENKINS_ARTIFACTORY_URL}", username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" + def rtServer = Artifactory.newServer url: "${env.JENKINS_PLATFORM_URL}".replaceFirst('/*$', '')+'/artifactory', username: "${env.JENKINS_ARTIFACTORY_USERNAME}", password: "${env.JENKINS_ARTIFACTORY_PASSWORD}" def buildInfo = Artifactory.newBuildInfo() buildInfo.name = "scripted:xrayScanFailBuildTrue test" buildInfo.number = "3"