{"id":1908,"date":"2017-12-06T10:54:15","date_gmt":"2017-12-06T10:54:15","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=1908"},"modified":"2020-01-09T09:42:34","modified_gmt":"2020-01-09T09:42:34","slug":"condition-with-task-in-ant","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/condition-with-task-in-ant\/","title":{"rendered":"Condition with Task in Ant"},"content":{"rendered":"<p><strong>scmuser created the topic: Condition with Task in Ant<\/strong><br \/>\nHi,<\/p>\n<p>How can i use conditions in Ant Task execution?<\/p>\n<p>Any idea?<\/p>\n<p><strong>tpatil replied the topic: Re: Condition with Task in Ant<\/strong><br \/>\n[i]<target name=\"check-props\"><\/p>\n<p>\t<!-- Ensure that entry doesn't exists in list --><br \/>\n        <condition property=\"entry-exists\"><br \/>\n             <contains string=\"${tag.list}\" substring=\"${build.label}\" \/><br \/>\n        <\/condition><br \/>\n        <fail if=\"entry-exists\" message=\"Entry already exists.Please specify another.\" \/><\/p>\n<p>\t<!-- Ensure dir is configured correctly and exists--><br \/>\n        <condition property=\"dir-configured\"><br \/>\n            <and><br \/>\n                <isset property=\"dir\" \/><br \/>\n                <available file=\"${dir}\" type=\"dir\" \/><br \/>\n            <\/and><br \/>\n        <\/condition><br \/>\n        <fail unless=\"dir-configured\" message=\"dir not configured\" \/><\/p>\n<p><\/target><\/p>\n<p><!-- Execute the ant based on condition is set or not --><br \/>\n<target name=\"-set-props-if-set\" if=\"property1\">\n\t    <property name=\"property2\" value=\"string1\"\/>\n\t    <property name=\"property3\" value=\"string2\"\/>\n<\/target><\/p>\n<p><target name=\"-set-props-if-not-set\" unless=\"property1\">\n\t    <property name=\"property2\" value=\"string2\"\/>\n\t    <property name=\"property3\" value=\"string1\"\/>\n<\/target>[\/i]<\/p>\n<p><strong>rajeshkumar replied the topic: Re: Condition with Task in Ant<\/strong><br \/>\nHi,<\/p>\n<p>I guess questions was based on applying condition for Aant TASK instead of Ant Target. Following ways i mean using <condition> you can set the conditional properties value but set condition with TASK.<\/p>\n<p>There is one external lib ant-contrib which can be used to put conditional Task such you can find more details in links below&#8230;..<br \/>\n<a href=\"http:\/\/ant-contrib.sourceforge.net\/tasks\/tasks\/if.html\" target=\"_blank\" rel=\"noopener\">ant-contrib.sourceforge.net\/tasks\/tasks\/if.html<\/a><br \/>\nRegards,<br \/>\nRajesh Kumar<br \/>\nTwitt me @ <a href=\"http:\/\/twitter.com\/RajeshKumarIn\" target=\"_blank\" rel=\"noopener\">twitter.com\/RajeshKumarIn<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>scmuser created the topic: Condition with Task in Ant Hi, How can i use conditions in Ant Task execution? Any idea? tpatil replied the topic: Re: Condition with Task in&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[12],"tags":[209],"class_list":["post-1908","post","type-post","status-publish","format-standard","hentry","category-apache-ant","tag-ant"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/1908","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=1908"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/1908\/revisions"}],"predecessor-version":[{"id":1909,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/1908\/revisions\/1909"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=1908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=1908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=1908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}