Search in sources :

Example 21 with CIBuildTrigger

use of com.redhat.jenkins.plugins.ci.CIBuildTrigger in project jms-messaging-plugin by jenkinsci.

the class SharedMessagingPluginIntegrationTest method _testSimpleCIEventTriggerOnPipelineJobWithGlobalEnvVarInTopic.

public void _testSimpleCIEventTriggerOnPipelineJobWithGlobalEnvVarInTopic() throws Exception {
    j.jenkins.getGlobalNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("MY_TOPIC_ID", "MY_UUID")));
    WorkflowJob jobA = j.jenkins.createProject(WorkflowJob.class, "jobA");
    jobA.setDefinition(new CpsFlowDefinition("node('master') {\n sleep 10\n}", true));
    attachTrigger(new CIBuildTrigger(false, Collections.singletonList(getSubscriberProviderData("$MY_TOPIC_ID", null, "CI_TYPE = 'code-quality-checks-done' and CI_STATUS = 'failed'"))), jobA);
    FreeStyleProject jobB = j.createFreeStyleProject();
    jobB.getPublishersList().add(new CIMessageNotifier(getPublisherProviderData("$MY_TOPIC_ID", MessageUtils.MESSAGE_TYPE.CodeQualityChecksDone, "CI_STATUS = failed", "Hello World")));
    j.buildAndAssertSuccess(jobB);
    waitUntilScheduledBuildCompletes();
    j.assertBuildStatusSuccess(jobA.getLastBuild());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) CIMessageNotifier(com.redhat.jenkins.plugins.ci.CIMessageNotifier) CIBuildTrigger(com.redhat.jenkins.plugins.ci.CIBuildTrigger) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) FreeStyleProject(hudson.model.FreeStyleProject) EnvironmentVariablesNodeProperty(hudson.slaves.EnvironmentVariablesNodeProperty)

Example 22 with CIBuildTrigger

use of com.redhat.jenkins.plugins.ci.CIBuildTrigger in project jms-messaging-plugin by jenkinsci.

the class SharedMessagingPluginIntegrationTest method _testSimpleCIEventTriggerWithCheckOnPipelineJobWithGlobalEnvVarInTopic.

public void _testSimpleCIEventTriggerWithCheckOnPipelineJobWithGlobalEnvVarInTopic() throws Exception {
    j.jenkins.getGlobalNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("MY_TOPIC_ID", "MY_UUID")));
    WorkflowJob jobA = j.jenkins.createProject(WorkflowJob.class, "jobA");
    jobA.setDefinition(new CpsFlowDefinition("node('master') {\n sleep 10\n}", true));
    attachTrigger(new CIBuildTrigger(false, Collections.singletonList(getSubscriberProviderData("$MY_TOPIC_ID", null, null, new MsgCheck(MESSAGE_CHECK_FIELD, MESSAGE_CHECK_VALUE)))), jobA);
    FreeStyleProject jobB = j.createFreeStyleProject();
    jobB.getPublishersList().add(new CIMessageNotifier(getPublisherProviderData("$MY_TOPIC_ID", null, null, MESSAGE_CHECK_CONTENT)));
    j.buildAndAssertSuccess(jobB);
    waitUntilScheduledBuildCompletes();
    j.assertBuildStatusSuccess(jobA.getLastBuild());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) CIMessageNotifier(com.redhat.jenkins.plugins.ci.CIMessageNotifier) CIBuildTrigger(com.redhat.jenkins.plugins.ci.CIBuildTrigger) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) MsgCheck(com.redhat.jenkins.plugins.ci.messaging.checks.MsgCheck) FreeStyleProject(hudson.model.FreeStyleProject) EnvironmentVariablesNodeProperty(hudson.slaves.EnvironmentVariablesNodeProperty)

Example 23 with CIBuildTrigger

use of com.redhat.jenkins.plugins.ci.CIBuildTrigger in project jms-messaging-plugin by jenkinsci.

the class AmqMessagingPluginWithFailoverIntegrationTest method testChangingJMSSelector.

@Test
public void testChangingJMSSelector() throws Exception {
    // Test changing a selector and make sure threads are handled correctly.
    FreeStyleProject jobA = j.createFreeStyleProject("receiver");
    jobA.getBuildersList().add(new Shell("echo CI_TYPE = $CI_TYPE"));
    jobA.addTrigger(new CIBuildTrigger(true, Collections.singletonList(new ActiveMQSubscriberProviderData(SharedMessagingPluginIntegrationTest.DEFAULT_PROVIDER_NAME, null, "CI_TYPE = 'code-quality-checks-done' and CI_STATUS = 'failed'", Collections.emptyList(), "CI_MESSAGE", 60))));
    jobA.getTrigger(CIBuildTrigger.class).start(jobA, true);
    List<Long> ids1 = getCurrentTriggerThreadIds("receiver");
    assertEquals("Trigger threads value selector size", 1, ids1.size());
    // Now change the selector.
    jobA.getTrigger(CIBuildTrigger.class).setProviderList(Collections.singletonList(new ActiveMQSubscriberProviderData(SharedMessagingPluginIntegrationTest.DEFAULT_PROVIDER_NAME, null, "CI_TYPE = 'code-quality-checks-done' and CI_STATUS = 'success'", Collections.emptyList(), "CI_MESSAGE", 60)));
    jobA.getTrigger(CIBuildTrigger.class).start(jobA, true);
    List<Long> ids2 = getCurrentTriggerThreadIds("receiver");
    assertEquals("Trigger threads changed selector size", 1, ids2.size());
    assertNotSame("Trigger threads new thread created", ids1.get(0), ids2.get(0));
}
Also used : Shell(hudson.tasks.Shell) ActiveMQSubscriberProviderData(com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData) CIBuildTrigger(com.redhat.jenkins.plugins.ci.CIBuildTrigger) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 24 with CIBuildTrigger

use of com.redhat.jenkins.plugins.ci.CIBuildTrigger in project jms-messaging-plugin by jenkinsci.

the class FedMsgMessagingPluginIntegrationTest method testTriggerWithComplexCheck.

@Test
public void testTriggerWithComplexCheck() throws Exception {
    String packages = "(acl|atk|atomic|atomic-devmode|attr|audit|erlang|audit-libs|authconfig|avahi|basesystem|bash|bash-completion|bind|bind99|biosdevname|boost|bridge-utils|bwidget|bzip2|ca-certificates|cairo|c-ares|ceph|checkpolicy|chkconfig|chrony|cloud-init|cloud-utils|cockpit|conntrack-tools|container-selinux|coreutils|cpio|cracklib|criu|crypto-policies|cryptsetup|cups|curl|cyrus-sasl|dbus|dbus-glib|dbus-python|dejavu-fonts|deltarpm|device-mapper-libs|device-mapper-multipath|device-mapper-persistent-data|dhcp|diffutils|ding-libs|dmidecode|dnf|dnsmasq|docker|dracut|dracut-network|e2fsprogs|efibootmgr|efivar|elfutils|emacs|etcd|ethtool|euca2ools|expat|fedora-logos|fedora-release|fedora-repos|file|filesystem|findutils|fipscheck|fipscheck-lib|flannel|fontconfig|fontpackages|freetype|fuse|gawk|gc|gcc|gdbm|gdisk|gdk-pixbuf2|GeoIP|GeoIP-GeoLite-data|gettext|glib2|glibc|glib-networking|glusterfs|gmp|gnupg|gnupg2|gnutls|gobject-introspection|gomtree|gperftools|gpgme|gpm|gpm-libs|graphite2|grep|grub2|gsettings-desktop-schemas|gssproxy|guile|gzip|harfbuzz|hawkey|hdparm|hicolor-icon-theme|hostname|http-parser|hwdata|initscripts|ipcalc|iproute|iptables|iputils|irqbalance|iscsi-initiator-utils|jansson|jasper|jbigkit|json-glib|kernel|kexec-tools|keyutils|keyutils-libs|kmod|krb5|krb5-libs|kubernetes|less|libacl|libaio|libarchive|libassuan|libatomic_ops|libblkid|libbsd|libcap|libcap-ng|libcgroup|libcom_err|libcomps|libcroco|libdatrie|libdb|libdrm|libedit|liberation-fonts|libev|libevent|libffi|libgcrypt|libglade2|libglvnd|libgpg-error|libgudev|libICE|libidn|libidn2|libiscsi|libjpeg-turbo|libksba|libldb|libmetalink|libmnl|libmodman|libmount|libndp|libnet|libnetfilter_conntrack|libnetfilter_cthelper|libnetfilter_cttimeout|libnetfilter_queue|libnfnetlink|libnfs|libnfsidmap|libnl3|libpcap|libpciaccess|libpng|libproxy|libpsl|libpwquality|librepo|libreport|libseccomp|libselinux|libsemanage|libsepol|libsigsegv|libSM|libsolv|libsoup|libssh2|libtalloc|libtasn1|libtdb|libtevent|libthai|libtiff|libtirpc|libtomcrypt|libtommath|libtool|libunistring|libunwind|libusb|libusbx|libuser|libutempter|libverto|libX11|libXau|libxcb|libXcomposite|libXcursor|libXdamage|libXext|libXfixes|libXft|libXi|libXinerama|libxml2|libXmu|libXrandr|libXrender|libxshmfence|libxslt|libXt|libXxf86misc|libXxf86vm|libyaml|linux-firmware|logrotate|lttng-ust|lua|lvm2|lz4|lzo|make|mcpp|mdadm|mesa|mokutil|mozjs17|mpfr|nano|ncurses|nettle|net-tools|NetworkManager|newt|nfs-utils|nghttp2|nmap|npth|nspr|nss|nss-pem|nss-softokn|nss-util|numactl|openldap|openssh|openssl|os-prober|ostree|p11-kit|pam|pango|passwd|pciutils|pcre|perl|perl-libs|pixman|policycoreutils|polkit|polkit-pkla-compat|popt|ppp|procps-ng|protobuf-c|publicsuffix-list|pygobject3|pyliblzma|pyserial|python|python3|python-beautifulsoup4|python-cffi|python-chardet|python-configobj|python-crypto|python-cryptography|python-cssselect|python-dateutil|python-decorator|python-dmidecode|python-docker-py|python-docker-pycreds|python-enum34|python-ethtool|python-html5lib|python-idna|python-iniparse|python-ipaddress|python-IPy|python-jinja2|python-jsonpatch|python-jsonpointer|python-lxml|python-markupsafe|python-oauthlib|python-paramiko|python-pip|python-ply|python-prettytable|python-progressbar|python-pyasn1|python-pycparser|python-pycurl|python-pygpgme|python-pysocks|python-pyudev|python-requestbuilder|python-requests|python-rhsm|python-setuptools|python-six|python-slip|python-urlgrabber|python-urllib3|python-websocket-client|pyxattr|PyYAML|qemu|qrencode|quota|readline|rpcbind|rpm|rsync|runc|samba|sed|selinux-policy|setools|setup|sgml-common|shadow-utils|shared-mime-info|shim-signed|skopeo|skopeo-containers|slang|snappy|socat|sqlite|sssd|subscription-manager|sudo|systemd|tar|tcl|tcp_wrappers|tcp_wrappers-libs|texinfo|tk|tmux|tuned|tzdata|usermode|userspace-rcu|ustr|util-linux|vim|virt-what|wayland|which|xfsprogs|xorg-x11-server-utils|xorg-x11-xauth|xorg-x11-xinit|xz|yum|yum-metadata-parser|zlib)";
    FreeStyleProject jobA = j.createFreeStyleProject();
    jobA.getBuildersList().add(new Shell("echo CI_MESSAGE = $CI_MESSAGE"));
    attachTrigger(new CIBuildTrigger(true, Collections.singletonList(getSubscriberProviderData("org.fedoraproject.dev.logger.log", null, null, new MsgCheck("$.commit.repo", packages)))), jobA);
    File privateKey = File.createTempFile("ssh", "key");
    FileUtils.copyURLToFile(FedmsgRelayContainer.class.getResource("FedmsgRelayContainer/unsafe"), privateKey);
    Files.setPosixFilePermissions(privateKey.toPath(), singleton(OWNER_READ));
    File ssh = File.createTempFile("jenkins", "ssh");
    FileUtils.writeStringToFile(ssh, "#!/bin/sh\n" + "exec ssh -o StrictHostKeyChecking=no -i " + privateKey.getAbsolutePath() + " fedmsg2@" + fedmsgRelay.getSshIPAndPort() + " fedmsg-logger " + " \"$@\"");
    Files.setPosixFilePermissions(ssh.toPath(), new HashSet<>(Arrays.asList(OWNER_READ, OWNER_EXECUTE)));
    System.out.println(FileUtils.readFileToString(ssh));
    ProcessBuilder gitLog1Pb = new ProcessBuilder(ssh.getAbsolutePath(), "--message='{\"commit\": " + "{\"branch\": \"f26\", " + " \"repo\": \"erlang\"" + "}\n" + "}\'", "--json-input");
    String output = stringFrom(logProcessBuilderIssues(gitLog1Pb, "ssh"));
    System.out.println(output);
    waitUntilScheduledBuildCompletes();
    FreeStyleBuild lastBuild = jobA.getLastBuild();
    j.assertBuildStatusSuccess(lastBuild);
    j.assertLogContains("erlang", lastBuild);
}
Also used : Shell(hudson.tasks.Shell) CIBuildTrigger(com.redhat.jenkins.plugins.ci.CIBuildTrigger) FedmsgRelayContainer(com.redhat.jenkins.plugins.ci.integration.fixtures.FedmsgRelayContainer) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) MsgCheck(com.redhat.jenkins.plugins.ci.messaging.checks.MsgCheck) File(java.io.File) Test(org.junit.Test)

Example 25 with CIBuildTrigger

use of com.redhat.jenkins.plugins.ci.CIBuildTrigger in project jms-messaging-plugin by jenkinsci.

the class SharedMessagingPluginIntegrationTest method _testDisabledJobDoesNotGetTriggeredWithCheck.

public void _testDisabledJobDoesNotGetTriggeredWithCheck() throws Exception {
    FreeStyleProject jobA = j.createFreeStyleProject();
    attachTrigger(new CIBuildTrigger(false, Collections.singletonList(getSubscriberProviderData(null, null, null, new MsgCheck(MESSAGE_CHECK_FIELD, MESSAGE_CHECK_VALUE)))), jobA);
    jobA.getBuildersList().add(new Shell("echo job ran"));
    jobA.disable();
    FreeStyleProject jobB = j.createFreeStyleProject();
    jobB.getPublishersList().add(new CIMessageNotifier(getPublisherProviderData(null, null, null, MESSAGE_CHECK_CONTENT)));
    j.buildAndAssertSuccess(jobB);
    Thread.sleep(5000);
    assertThat(jobA.getBuilds(), Matchers.iterableWithSize(0));
    jobA.enable();
    Thread.sleep(3000);
    j.buildAndAssertSuccess(jobB);
    waitUntilScheduledBuildCompletes();
    j.assertBuildStatusSuccess(jobA.getLastBuild());
    j.assertLogContains("echo job ran", jobA.getLastBuild());
}
Also used : Shell(hudson.tasks.Shell) CIMessageNotifier(com.redhat.jenkins.plugins.ci.CIMessageNotifier) CIBuildTrigger(com.redhat.jenkins.plugins.ci.CIBuildTrigger) FreeStyleProject(hudson.model.FreeStyleProject) MsgCheck(com.redhat.jenkins.plugins.ci.messaging.checks.MsgCheck)

Aggregations

CIBuildTrigger (com.redhat.jenkins.plugins.ci.CIBuildTrigger)35 FreeStyleProject (hudson.model.FreeStyleProject)34 Shell (hudson.tasks.Shell)26 CIMessageNotifier (com.redhat.jenkins.plugins.ci.CIMessageNotifier)24 MsgCheck (com.redhat.jenkins.plugins.ci.messaging.checks.MsgCheck)14 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)10 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)10 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)9 StringParameterDefinition (hudson.model.StringParameterDefinition)8 FreeStyleBuild (hudson.model.FreeStyleBuild)6 Test (org.junit.Test)6 CIMessageBuilder (com.redhat.jenkins.plugins.ci.CIMessageBuilder)3 ActiveMQSubscriberProviderData (com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData)3 EnvironmentVariablesNodeProperty (hudson.slaves.EnvironmentVariablesNodeProperty)3 FedmsgRelayContainer (com.redhat.jenkins.plugins.ci.integration.fixtures.FedmsgRelayContainer)2 MessagingProviderOverrides (com.redhat.jenkins.plugins.ci.messaging.MessagingProviderOverrides)2 BooleanParameterDefinition (hudson.model.BooleanParameterDefinition)2 ParametersAction (hudson.model.ParametersAction)2 StringParameterValue (hudson.model.StringParameterValue)2 File (java.io.File)2